from os import name
import os
from flask import Flask, render_template, url_for, request, session, redirect
import pandas as pd
import csv
import numpy as np
from datetime import date, datetime
import datetime
from Recom import get_correlation_coefficents, rank_items, tannisyutoku, Similarity, Informative, Concentration, Credibility, kousinn,\
                  video_kousinn, Credibility_video, Video_Concentration, kousinn01, video_kousinn00, tannisyutoku0A, tannisyutoku0B,\
                  tannisyutoku0C, tannisyutoku0D, tannisyutoku1A, tannisyutoku1B, tannisyutoku1C, tannisyutoku2A,tannisyutoku2B,\
                  tannisyutoku3A, tannisyutoku4A, tannisyutoku4B, tannisyutoku5A, tannisyutoku5B, tannisyutoku5C, tannisyutoku6A,\
                  tannisyutoku6B, tannisyutoku6C, tannisyutoku6D, tannisyutoku6E, tannisyutoku6F
from hashlib import sha256
from model.models import Student
from model.database import db_session
import key
import requests
from bs4 import BeautifulSoup
import re
import urllib.parse

app = Flask(__name__)
app.secret_key = key.SECRET_KEY

teacher_df = pd.read_csv("Book1.csv",encoding="cp932", header=None)
kyouin = teacher_df[0].unique().tolist()

#最初のログイン画面（スタート画面）（最初にアクセスしたときに表示させる）
# ここでは，シラバス作成か，学生かを選択してもらう．
@app.route("/")
@app.route('/normal')
def normal():
    return render_template("normal.html")

@app.route('/teacher')
def teacher():
    return render_template('teacher.html', tantou_list = kyouin)

@app.route('/subject', methods=['GET', 'POST'])
def subject():
    tantou_name = request.form.get('tantousya')
    session['teacher'] = tantou_name

    df_tantou = teacher_df[teacher_df[0]==tantou_name]
    # 選択された名前の授業をリスト（kamoku）にいれる
    kamoku = df_tantou[1].tolist()

    return render_template('subject.html', tantou_name = tantou_name, kamoku = kamoku, name = tantou_name)

@app.route('/result', methods=['GET', 'POST'])
def result():
    #前ページで選択された教員の名前を保存（session['teacher]に）
    tantou_name = session['teacher']
    print(tantou_name)

    #選択された授業タイトル
    kamoku_name = request.form.get('tantou_subject')
    session['kamoku_name'] = kamoku_name
    print(kamoku_name)

    # 授業タイトルの英語版
    kamoku_eng = request.form.get('english_name')
    session['kamoku_eng'] = kamoku_eng

    # 科目区分
    subject_area = request.form.get('subject_area')
    session['subject_area'] = subject_area

    # 配当学年
    dividend_grade = request.form.get('dividend_grade')
    session['dividend_grade'] = dividend_grade

    # 職種
    occupation = request.form.get('occupation')
    session['occupation'] = occupation

    # 所属
    belong = request.form.get('belong')
    session['belong'] = belong

    # 開講学期
    semester = request.form.get('semester')
    session['semester'] = semester

    # 単位数
    units = request.form.get('units')
    session['units'] = units

    # 単位区分
    unit_area = request.form.get('unit_area')
    session['unit_area'] = unit_area

    # 関連する学習・教育目標
    educational_goal = request.form.get('educational_goal')
    session['educational_goal'] = educational_goal

    # 授業の目標/授業概要
    outline = request.form.get('outline')
    session['outline'] = outline

    # 学生の到達目標
    student_goal = request.form.get('student_goal')
    session['student_goal'] = student_goal

    #授業計画をリストで取得し，データフレームに
    text = request.form.getlist('item1')
    session['text'] = text
    # 授業計画の部分をデータフレームにする
    plan_df = pd.DataFrame(text)
    os.makedirs("csv_save", exist_ok=True)
    plan_df.to_csv("csv_save/"+kamoku_name+".csv", encoding='cp932', index=None,header=None)

    #キーワードをリストで取得し，データフレームに
    keyword = request.form.getlist('item2')
    true_keyword = list(filter(None, keyword))
    session['true_keyword'] = true_keyword
    # print(true_keyword)
    # key_df = pd.DataFrame(true_keyword)
    # df_key = key_df.to_html()

    # 成績評価基準
    evaluation = request.form.get('evaluation')
    session['evaluation'] = evaluation

    # 教科書・教材参考書等
    materials = request.form.get('materials')
    session['materials'] = materials

    # 関連科目・履修条件等
    requirements = request.form.get('requirements')
    session['requirements'] = requirements

    # 履修上の注意事項や学習上の助言
    notes = request.form.get('notes')
    session['notes'] = notes

    # 学生からの質問への対応方法
    responce = request.form.get('responce')
    session['responce'] = responce

    return render_template('syllabus.html', sub_name=kamoku_name,  teacher=tantou_name, kamoku_eng=kamoku_eng, subject_area=subject_area, dividend_grade=dividend_grade, occupation=occupation, belong=belong, semester=semester, units=units, unit_area=unit_area,\
                                            educational_goal=educational_goal,outline=outline, student_goal=student_goal, plan_df=text, keyword=true_keyword, evaluation=evaluation, materials=materials, requirements=requirements, notes=notes, responce=responce)


@app.route('/hozon', methods=['POST'])
def hozon():
    tantou_name = session['teacher']

    kamoku_name = session['kamoku_name']

    kamoku_eng = session['kamoku_eng']

    subject_area = session['subject_area']

    dividend_grade = session['dividend_grade']

    occupation = session['occupation']

    belong = session['belong']

    semester = session['semester']

    units = session['units']

    unit_area = session['unit_area']

    educational_goal = session['educational_goal']

    outline = session['outline']

    student_goal = session['student_goal']

    text = session['text']

    true_keyword = session['true_keyword']

    evaluation = session['evaluation']

    materials = session['materials']

    requirements = session['requirements']

    notes = session['notes']

    responce = session['responce']

    df_moto = pd.read_csv("moto_sylla.csv", encoding='cp932')
    df_moto.reset_index
    data_list = [kamoku_name, kamoku_eng, subject_area, dividend_grade, tantou_name, semester, units, unit_area, educational_goal, outline, student_goal, text, true_keyword, evaluation, materials, requirements, notes, responce]

    data_list[11] = '\n'.join(data_list[11])
    data_list[12] = ','.join(data_list[12])
    class_name = data_list[0]
    number = df_moto.index[df_moto['講義名称']==class_name][0]
    df_moto.loc[number,'講義名称']=data_list[0]
    df_moto.loc[number,"授業科目名（英語）"] = data_list[1]
    df_moto.loc[number,'科目区分'] = data_list[2]
    df_moto.loc[number,'配当学年'] = data_list[3]
    df_moto.loc[number,'代表教員名'] = data_list[4]
    df_moto.loc[number,'開講学期'] = data_list[5]
    df_moto.loc[number,'単位数'] = data_list[6]
    df_moto.loc[number,'単位区分'] = data_list[7]
    df_moto.loc[number,'関連する学習・教育目標'] = data_list[8]
    df_moto.loc[number,'授業の目標／授業概要'] = data_list[9]
    df_moto.loc[number,'学生の到達目標'] = data_list[10]
    df_moto.loc[number,'授業計画'] = data_list[11]
    df_moto.loc[number,'キーワード'] = data_list[12]
    df_moto.loc[number,'成績評価基準'] = data_list[13]
    df_moto.loc[number,'教科書・教材参考書等'] = data_list[14]
    df_moto.loc[number,'関連科目・履修条件等'] = data_list[15]
    df_moto.loc[number,'履修上の注意事項や学習上の助言'] = data_list[16]
    df_moto.loc[number,'学生からの質問への対応方法'] = data_list[17]

    df_moto.to_csv("syllabus.csv", encoding='cp932', index=False)

    ###################################################################
    # スクレイピングのところ
    os.makedirs("Tameshi", exist_ok=True)

    sub_title = pd.read_csv("csv_save/"+kamoku_name+".csv", encoding='cp932', header=None)
    sub_list =sub_title.iloc[:,0]
    # print(sub_list)

    hp_title = [[] for _ in range(len(sub_list))]
    hp_url = [[] for _ in range(len(sub_list))]

    for j in range(len(sub_list)):
        search_word = sub_list[j]
        pages_num = 15+1

        url = f'https://www.google.co.jp/search?hl=ja&num={pages_num}&q={search_word}'
        request =requests.get(url)

        soup = BeautifulSoup(request.text, 'html.parser')
        search_Results = soup.select('.kCrYT > a')
        search_title = soup.select('.BNeawe.vvjwJb.AP7Wnd')

        for i in range(len(sub_list)):
            #なんか変な文字が入るので除く       
            site_url = str(search_Results[i].get('href').split('&sa=U&')[0].replace('/url?q=', ''))
            #URLに日本語が含まれている場合、エンコードされているのでデコードする
            site_url = urllib.parse.unquote(urllib.parse.unquote(site_url))
        
            #いらない文字を削除
            site_title = str(search_title[i]).strip('<div class="BNeawe vvjwJb AP7Wnd">').strip('</')
            #URLに日本語が含まれている場合、エンコードされているのでデコードする
            site_title = urllib.parse.unquote(urllib.parse.unquote(site_title))
            
            #print(site_title)
            hp_title[j].append(site_title)
            hp_url[j].append(site_url)
        
        for i in range(len(sub_list)):
            df = pd.DataFrame({'HPtitle':hp_title[j],'HPurl':hp_url[j]})
            df.to_csv(f'Tameshi/kyouzai_{i}.csv',index=None,encoding='utf-8-sig')
    ###################################################################

    # こっちはhtmlで保存するようにする
    # 入力された状態のhtmlを html にいれる．
    html = render_template('true_syllabus.html', sub_name=kamoku_name,  teacher=tantou_name, kamoku_eng=kamoku_eng, subject_area=subject_area, dividend_grade=dividend_grade, occupation=occupation, belong=belong, semester=semester, units=units, unit_area=unit_area,\
                                            educational_goal=educational_goal,outline=outline, student_goal=student_goal, plan_df=text, keyword=true_keyword, evaluation=evaluation, materials=materials, requirements=requirements, notes=notes, responce=responce)
    
    os.makedirs("html_save", exist_ok=True)
    # 上で作成した html を aiueo.html という名前で保存する．（このaiueo.htmlを科目名に変更するかどうか）
    with open("html_save/aiueo.html",mode="w",encoding="utf-8") as f:
        f.write(str(html))

    return render_template('teacher.html', tantou_list = kyouin)



# start.html は学生用のログイン画面
@app.route("/start")
def start():
   status = request.args.get("status")
   return render_template("start.html",status=status)

#ログインするときに行う部分（データベースに登録されているかどうかの確認）
# 登録してあれば，推薦．　してないと，新規登録をしてもらうようにする．
@app.route("/login", methods=["POST"])
def login():
    user_name = request.form.get("user_name")
    password = request.form["password"]
    if len(user_name) == 0 or len(password) == 0:
        return redirect(url_for("start", status="no_text"))
    hashed_password = sha256((user_name + password + key.SALT).encode("utf-8")).hexdigest()
    
    user_found = False
    with open('user.csv','r') as check_file:
        reader = csv.reader(check_file)
        for row in reader:
            if row[0] == user_name:
                if row[1] == hashed_password:
                    session['user_name'] = user_name
                    user_found = True
                    break
                else:
                    user_found = True
                    status = "wrong_password"
                    break

    if user_found == True:
        return redirect(url_for('top'))
    else:
        status = "user_notfound"
        return redirect(url_for('start', status = status))

    # with open(file_path+'user.csv','r') as check_file:
    #     reader = csv.reader(check_file)
    #     if any([row[0] == user_name for row in reader]):
    #         if any(row[1] == hashed_password for row in reader]):
    
    # else:
    #     user_name = request.form.get("user_name")
    #     password = request.form["password"]
    #     hashed_password = sha256((user_name + password + key.SALT).encode("utf-8")).hexdigest()
    #     with open('user.csv','r') as check_file:
    #         reader = csv.reader(check_file)
    #         for row in reader:
                # if row[0] == user_name and row[1] == hashed_password:
                #     session['user_name'] = user_name
                #     return redirect(url_for('top'))
                # elif row[0] == user_name and row[1] != hashed_password:
                #     return redirect(url_for('start', status = "wrong_password"))
                # elif row[0] != user_name:
                #     return redirect(url_for('start', status = "user_notfound"))

                # row[0]が学籍番号，row[1]がハッシュ化パスワード
                # if user_name in row:
                #     print("存在します")
                #     if row[1] == hashed_password:
                #         session['user_name'] = user_name
                #         return redirect(url_for('top'))
                #     else:
                #         return redirect(url_for('start', status = "wrong_password"))
                
                # else:
                #     return redirect(url_for('start', status = "user_notfound"))


    #DB使う版
#    user_name = request.form["user_name"]
#    user = Student.query.filter_by(user_name=user_name).first()
#    if user:
#       password = request.form["password"]
#       hashed_password = sha256((user_name + password + key.SALT).encode("utf-8")).hexdigest()
#       if user.hashed_password == hashed_password:
#          session["user_name"] = user_name
#          # topのところに app.py の index 部分をいれる
#          return redirect(url_for("top"))
#       else:
#          return redirect(url_for("start",status="wrong_password"))
#    else:
#       return redirect(url_for("start",status="user_notfound"))

#新規登録のところ（GET）
@app.route("/newcomer")
def newcomer():
   status = request.args.get("status")
   return render_template("newcomer.html",status=status)

# 学籍番号，パスワードが入力されていないと 入力してください を返すようにする（POST）
@app.route("/registar", methods=["POST"])
def registar():
    user_name = request.form.get("user_name")
    password = request.form["password"]
    if len(user_name) == 0 or len(password) == 0:
        return redirect(url_for("newcomer", status="no_text"))
    hashed_password = sha256((user_name + password + key.SALT).encode("utf-8")).hexdigest()
    user_set = [user_name, hashed_password]
    with open('user.csv', 'r') as check_file:
        reader = csv.reader(check_file)
        if any([row[0] == user_name for row in reader]):
            return redirect(url_for("newcomer", status="exist_user"))
    with open("user.csv", 'a', encoding="cp932") as user_file:
        writer = csv.writer(user_file)
        writer.writerow(user_set)
        session['user_name'] = user_name
    return redirect(url_for("get"))

    # DB使う版
    #   user = Student.query.filter_by(user_name=user_name).first()
    #   if user:
    #      # ユーザが登録されていたら，index部分に飛ばすようにするかも
    #      return redirect(url_for("newcomer",status="exist_user"))
    #   else:
    #      if len(request.form["password"]) == 0:
    #         #パスワードが空白の場合書き直す
    #         return redirect(url_for("newcomer", status="no_text"))
    #      else:   
    #         password = request.form["password"]
    #         hashed_password = sha256((user_name + password + key.SALT).encode("utf-8")).hexdigest()
    #         user = Student(user_name, hashed_password)
    #         print(user)
    #         try:
    #            db_session.add(user)
    #            db_session.commit()
    #         except:
    #            db_session.rollback()
    #         session["user_name"] = user_name
    #         return redirect(url_for("get"))

# ログアウト用
@app.route("/logout")
def logout():
   session.pop("user_name", None)
   return redirect(url_for("start",status="logout"))
      

# 成績入力させるところ (GET)
@app.route('/get',methods=['GET'])
def get():
   if "user_name" in session:
      name = session["user_name"]
      return render_template('grade_entry.html', title = '成績チェック(GET)', name = name, message='成績入力部分')
   else:
      return redirect(url_for("start", status = "logout"))

# 成績，希望業種を入力（POST）
@app.route('/touroku', methods=['POST'])
def touroku():
    #リストを初期化することで，csvに追記する際に新しくする
    name = session["user_name"]
    usr_grade=[]

    edu1 = request.form.get('edu1'); edu2 = request.form.get('edu2'); eco1 = request.form.get('eco1'); soc1 = request.form.get('soc1'); law1 = request.form.get('law1'); sci_tech = request.form.get('sci_tech')

    env1 = request.form.get('env1'); japanese = request.form.get('japanese');compare1 = request.form.get('compare1'); health_sci_exe = request.form.get('health_sci_exe'); psycho1 = request.form.get('psycho1'); health_sci1 = request.form.get('health_sci1')

    math1 = request.form.get('math1'); math2 = request.form.get('math2'); psy1 = request.form.get('psy1'); psy2 = request.form.get('psy2'); chemi1 = request.form.get('chemi1'); chemi2 = request.form.get('chemi2')

    biology = request.form.get('biology'); phy1_exe = request.form.get('phy1_exe'); math_exe = request.form.get('math_exe'); chemi_exp = request.form.get('chemi_exp'); phy_exp = request.form.get('phy_exp'); ba_eng1 = request.form.get('ba_eng1')

    ba_eng2 = request.form.get('ba_eng2'); ba_eng3 = request.form.get('ba_eng3'); ba_eng4 = request.form.get('ba_eng4'); german1 = request.form.get('german1'); german2 = request.form.get('german2'); china1 = request.form.get('china1')

    china2 = request.form.get('china2'); career = request.form.get('career'); algebra1 = request.form.get('algebra1') ;algebra2 = request.form.get('algebra2'); info_math1 = request.form.get('info_math1'); info_math2 = request.form.get('info_math2')

    pro_stat = request.form.get('pro_stat'); complex_ana = request.form.get('complex_ana'); intro_info_sys = request.form.get('intro_info_sys'); com_base = request.form.get('com_base'); programming1 = request.form.get('programming1'); programming1_exe = request.form.get('programming1_exe')

    algo_data = request.form.get('algo_data'); electric_circuit = request.form.get('electric_circuit'); eco2 = request.form.get('eco2') ;soc2 = request.form.get('soc2'); law2 = request.form.get('law2'); env2 = request.form.get('env2')

    comm_logic = request.form.get('comm_logic'); litera1 = request.form.get('litera1'); compare2 = request.form.get('compare2'); psycho2 = request.form.get('psycho2'); ethics = request.form.get('ethics'); philo = request.form.get('philo')

    compre_eng1 = request.form.get('compre_eng1'); compre_eng2 = request.form.get('compre_eng2'); compre_eng3 = request.form.get('compre_eng3'); compre_eng4 = request.form.get('compre_eng4'); topic_semi1 = request.form.get('topic_semi1'); topic_semi2 = request.form.get('topic_semi2')

    diff_equ = request.form.get('diff_equ'); fourier = request.form.get('fourier'); info_theory = request.form.get('info_theory'); DSP = request.form.get('DSP'); elec_circuit = request.form.get('elec_circuit'); logic_circuit_base = request.form.get('logic_circuit_base')

    info_sys_exp1 = request.form.get('info_sys_exp1'); programming2 = request.form.get('programming2'); programming2_exe = request.form.get('programming2_exe'); programming3 = request.form.get('programming3'); programming3_exe = request.form.get('programming3_exe'); com_archi = request.form.get('com_archi')

    compiler = request.form.get('compiler'); com_net = request.form.get('com_net'); iot_sys = request.form.get('iot_sys'); commu_method = request.form.get('commu_method'); data_data = request.form.get('data_data'); image_processing = request.form.get('image_processing')

    const_japan = request.form.get('const_japan'); tech_soc = request.form.get('tech_soc'); toyama_japan = request.form.get('toyama_japan'); litera2 = request.form.get('litera2'); modern_his = request.form.get('modern_his'); inter_rela = request.form.get('inter_rela')

    comm_soc = request.form.get('comm_soc'); health_sci2 = request.form.get('health_sci2'); spe_eng1 = request.form.get('spe_eng1'); spe_eng2 = request.form.get('spe_eng2'); spe_eng3 = request.form.get('spe_eng3'); spe_eng4 = request.form.get('spe_eng4')

    presen = request.form.get('presen'); engi_ethic = request.form.get('engi_ethic'); business_manage = request.form.get('business_manage'); interA = request.form.get('interA'); interB = request.form.get('interB'); tech_eng = request.form.get('tech_eng')

    spe_info_sys = request.form.get('spe_info_sys'); info_sys_exp2 = request.form.get('info_sys_exp2'); grad_research1 = request.form.get('grad_research1'); iot_prog = request.form.get('iot_prog'); logic_circuit_app = request.form.get('logic_circuit_app'); embedded = request.form.get('embedded')

    prog_lan = request.form.get('prog_lan'); queueing = request.form.get('queueing'); soft_engi = request.form.get('soft_engi'); opera_sys = request.form.get('opera_sys'); hum_inter = request.form.get('hum_inter'); bioinfo = request.form.get('bioinfo')

    machine_learning = request.form.get('machine_learning'); nume_ana = request.form.get('nume_ana'); ope_sys = request.form.get('ope_sys'); info_global = request.form.get('info_global'); grad_research2 = request.form.get('grad_research2')

    # 就職希望の部分
    hope = request.form.get('industry_hope')

    usr_grade.extend([name, 
                        edu1, edu2, eco1, soc1, law1, sci_tech,
                        env1, japanese, compare1, health_sci_exe, psycho1, health_sci1,
                        math1, math2, psy1, psy2, chemi1, chemi2,
                        biology, phy1_exe, math_exe, chemi_exp, phy_exp, ba_eng1,
                        ba_eng2, ba_eng3, ba_eng4, german1, german2, china1,
                        china2, career, algebra1, algebra2, info_math1, info_math2,
                        pro_stat, complex_ana, intro_info_sys, com_base, programming1, programming1_exe,
                        algo_data, electric_circuit, eco2, soc2, law2, env2,
                        comm_logic, litera1, compare2, psycho2, ethics, philo,
                        compre_eng1, compre_eng2, compre_eng3, compre_eng4, topic_semi1, topic_semi2,
                        diff_equ, fourier, info_theory, DSP, elec_circuit, logic_circuit_base,
                        info_sys_exp1, programming2, programming2_exe, programming3, programming3_exe, com_archi,
                        compiler, com_net, iot_sys, commu_method, data_data, image_processing,
                        const_japan, tech_soc, toyama_japan, litera2, modern_his, inter_rela,
                        comm_soc, health_sci2, spe_eng1, spe_eng2, spe_eng3, spe_eng4,
                        presen, engi_ethic, business_manage, interA, interB, tech_eng,
                        spe_info_sys, info_sys_exp2, grad_research1, iot_prog, logic_circuit_app, embedded,
                        prog_lan, queueing, soft_engi, opera_sys, hum_inter, bioinfo,
                        machine_learning, nume_ana, ope_sys, info_global, grad_research2, hope])

    #入力されたデータを data.csv ファイルに保存する．
    with open('data.csv','a',encoding='cp932',newline='\n') as file:
        writer = csv.writer(file)
        writer.writerow(usr_grade)
    return redirect(url_for("top"))
    
    #    return render_template('grade_entry.html', title ='成績チェック(POST)', name = name, message ='入力ありがとう')



@app.route('/top')
def top():
   if "user_name" in session:
      # 入力された学籍番号を name に入れておく（文字列）
      name = session["user_name"]
      session['user'] = name

      # 業種ありのものを，業種部分削って結合する（フラグ部分はまだ実装していない）
      nondel_data2017 = pd.read_csv("kai_2017_04.csv", encoding="cp932")
      nondel_data2017 = nondel_data2017.drop(nondel_data2017.columns[-1], axis=1)
      nondel_data2018 = pd.read_csv("kai_2018_04.csv", encoding="cp932").drop([0, 1, 2])#dropで必要のない行を削除する
      nondel_data2018 = nondel_data2018.drop(nondel_data2018.columns[-1], axis=1)
      nondel_data2019 = pd.read_csv("kai_2019_04.csv", encoding="cp932").drop([0, 1, 2])#dropで必要のない行を削除する
      nondel_data2019 = nondel_data2019.drop(nondel_data2019.columns[-1], axis=1)
      # 3年分合わせたデータ（上から古い学籍番号の人）
      nondel_data_all = pd.concat([nondel_data2017, nondel_data2018, nondel_data2019], axis=0, sort = False).drop('学籍番号', axis=1)

      # 必選別，単位数，配当学年を削ったやつ
      data2017 = pd.read_csv('kai_2017_04.csv', encoding='cp932').drop([0, 1, 2])
      data2018 = pd.read_csv('kai_2018_04.csv', encoding='cp932').drop([0, 1, 2])
      data2019 = pd.read_csv('kai_2019_04.csv', encoding='cp932').drop([0, 1, 2])

      # 過去の学生のデータ(今回は2017年と2018年の2年分)，2018と2017年のデータを縦に連結する
      data_kako = pd.concat([data2017, data2018, data2019], axis=0, sort = False)

      # ユーザが成績入力した際に出力される csvファイル
      user_data = pd.read_csv("data.csv",encoding="cp932", header=None)

      # 入力された学籍番号と成績・希望業種データを抽出
      data_ima = user_data[user_data[0].isin([int(name)])]
      data_ima.columns = data_kako.columns

      # 入力したユーザの希望業種の数値を抽出する
      industry = data_ima.iat[-1,-1]

      # ユーザの希望業種に応じて，それと同じ学生のデータを使用する
      if industry == 1:
         data_kako = data_kako[data_kako.loc[:,"業種"]==1]
      elif industry == 2:
         data_kako = data_kako[data_kako.loc[:,"業種"]==2]
      elif industry == 3:
         data_kako = data_kako[data_kako.loc[:,"業種"]==3]
      elif industry == 4:
         data_kako = data_kako[data_kako.loc[:,"業種"]==4]
      elif industry == 5:
         data_kako = data_kako[data_kako.loc[:,"業種"]==5]
      elif industry == 6:
         data_kako = data_kako[data_kako.loc[:,"業種"]==6]
      elif industry == 7:
         data_kako = data_kako[data_kako.loc[:,"業種"]==7]
      elif industry == 8:
         data_kako = data_kako[data_kako.loc[:,"業種"]==8]
      elif industry == 0:
         pass   
      
      # 過去の学生データとユーザのデータを結合（ユーザデータは一番上）
      data_gutya = pd.concat([data_ima, data_kako], axis=0, sort=False)  # 学籍番号付きのデータ

      # 列名指定で 業種 列を削除（最終列）
      # data_gutya.drop("業種", axis=1)

      # 名前指定じゃなくて最終列指定で削除
      data_gutya = data_gutya.drop(data_gutya.columns[-1],axis=1)

      # 学籍番号とってNaNを-1埋めしたデータ （履修していない科目に -1 を入れる）
      data_all = data_gutya.reset_index(drop=True).drop('学籍番号', axis=1).fillna(-1)  

      # いったんnumpyに（data_allの中身を）
      data_all_np = data_all.values

      #上のやつのコピーを data_all_calc に入れる
      data_all_calc = data_all_np.copy()

      #data_all_calcの-1以外のものを全て0に書き換える（履修した科目のものを 0 にして，履修していないものに -1 をいれている状態）
      data_all_calc[data_all_calc != -1] = 0

      # np.abs(data_all_cals)で data_all_calcの絶対値をとる．（ -1 → 1 になる →　履修していないものに 1 が立つようになる）
      # columnsには授業名を入れる
      # それらをデータフレームにして，data_train にいれる
      data_train = pd.DataFrame(np.abs(data_all_calc), columns=data_all.columns)

      #対象ユーザの部分を取得する（data_train_user にいれる）
      data_train_user = data_train[:1]

      # 科目数分繰り返す
      # 対象ユーザーの落単科目（data_all.iloc[0,i] == 0）に対して，0 を 1 に変える
      #　　→未履修科目と落単科目に対して 1 を立て，履修済み科目に対しては 0 を立てる
      for i in range(len(data_all.columns)):
         if data_all.iloc[0, i] == 0:
            data_train_user = data_train_user.replace({f'{data_train_user.columns[i]}': {0: 1}})
      
      # 区分のリスト
      df4 = ["0A", "0A", "0B", "0B", "0B", "0B", "0B", "0C", "0C", "0D", "0D", "0D", "1A", "1A", "1A", "1A", "1B", "1B", "1B", "1A", "1C",
            "1C", "1A", "2A", "2A", "2A", "2A", "2B", "2B", "2B", "2B", "3A", "4A", "4A", "4A", "4A", "4A", "4A", "4B", "5A", "5A", "5A",
            "5B", "5C", "0B", "0B", "0B", "0B", "0C", "0C", "0C", "0D", "0D", "0D", "2A", "2A", "2A", "2A", "3A", "3A", "4A", "4A", "5B",
            "5B", "5C", "5C", "5D", "6A", "6A", "6A", "6A", "6B", "6B", "6C", "6C", "6C", "6D", "6E", "0B", "0B", "0B", "0C", "0C", "0C",
            "0D", "0D", "2A", "2A", "2A", "2A", "3A", "3A", "3A", "3A", "3A", "3A", "5D", "5D", "5D", "6A", "6B", "6B", "6B", "6C", "6D",
            "6D", "6E", "6E", "6F", "6F", "6F", "6F", "5D"]

      # zero：総合科目
      zero = 19; zeroA = 2; zeroB = 2; zeroC = 2; zeroD = 2
      # iti：基礎科目
      iti = 13; itiA = 10; itiB = 2; itiC = 1
      # ni：外国語科目
      ni = 12; niA = 10; niB = 2
      # kyouyou：教養全体 ＝ 44
      kyouyou = zero + iti + ni
      # sann：キャリア形成科目
      sannA = 7
      # senmon：卒業研究２を除いた専門科目
      senmon = 71
      # yonn：専門基礎科目
      yonnA = 10; yonnB = 2
      # go：専門共通科目
      goA = 5; goB = 4; goC = 4; goD = 8
      # roku：専門科目
      rokuA = 5; rokuB = 6; rokuC = 4; rokuD = 2; rokuE = 2; rokuF = 4
      # sotuken：卒業研究２
      sotuken = 8
      # senmon_all：専門全部で必要な単位数 = 79
      senmon_all =senmon + sotuken 
      # all_all：全体の単位数
      all_all = 140

      zero_sum = 0; zeroA_sum = 0; zeroB_sum = 0 ; zeroC_sum = 0; zeroD_sum = 0
      iti_sum = 0; itiA_sum = 0; itiB_sum = 0; itiC_sum = 0
      niA_sum = 0; niB_sum = 0
      sannA_sum = 0
      yonnA_sum = 0; yonnB_sum = 0
      goA_sum = 0; goB_sum = 0; goC_sum = 0; goD_sum = 0
      rokuA_sum = 0; rokuB_sum = 0; rokuC_sum = 0; rokuD_sum = 0; rokuE_sum = 0; rokuF_sum = 0

      #現在の単位数を確認
      for i in range(len(data_train_user.columns)):
      # 履修済みor推薦済みの時（data_train_user.iloc[0,i] == 0）
      # nodel_data_all.iloc[2,i] は取得できる単位数が入っている
         if data_train_user.iloc[0,i] == 0:
            if df4[i] == '0A':
                  zeroA_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '0B':
                  zeroB_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '0C':
                  zeroC_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '0D':
                  zeroD_sum += nondel_data_all.iloc[2,i] 
            elif df4[i] == '1A':
                  itiA_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '1B':
                  itiB_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '1C':
                  itiC_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '2A':
                  niA_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '2B':
                  niB_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '3A':
                  sannA_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '4A':
                  yonnA_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '4B':
                  yonnB_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '5A':
                  goA_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '5B':
                  goB_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '5C':
                  goC_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '5D':
                  goD_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '6A':
                  rokuA_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '6B':
                  rokuB_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '6C':
                  rokuC_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '6D':
                  rokuD_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '6E':
                  rokuE_sum += nondel_data_all.iloc[2,i]
            elif df4[i] == '6F':
                  rokuF_sum += nondel_data_all.iloc[2,i]
            else:
                  pass
         else:
            pass

      all_sum = zeroA_sum + zeroB_sum + zeroC_sum +zeroD_sum + itiA_sum +itiB_sum + itiC_sum + niA_sum + niB_sum +\
                  sannA_sum + yonnA_sum + yonnB_sum + goA_sum + goB_sum + goC_sum + rokuA_sum + rokuB_sum + rokuC_sum +\
                     rokuD_sum + rokuE_sum + rokuF_sum
      
      # 現在の取得単位数を now_all_sum にコピーする
      now_all_sum = all_sum.copy()

      # 0番目のユーザ(対象ユーザ)
      target_user_index = 0 

      # Person関数で指定した学生とすべての学生の類似度を算出する
      # 学籍番号とってNaNを-1埋めしたデータ （履修していない科目に -1 を入れる）と target_user_index を使用する
      similarities = get_correlation_coefficents(data_all_np, target_user_index)

      # 予測評価値をもとにランキング(予測評価値も求める)
      rank = rank_items(data_all_np, similarities, target_user_index)

      # rank（予測評価値をもとにランキングしたもの）をデータフレームにする（index と predict を columns にする）
      rank_df = pd.DataFrame(rank,columns=['index','predict'])

      # rank_df の index部分を科目名に変化させる
      for i in range(len(rank_df.index)):
         rank_df = rank_df.replace({'index':{rank_df.iloc[i,0]:data_all.columns[rank_df.iloc[i,0]]}})

      mirisyuu_list = []#まだ履修していない科目リスト(予測評価順)
      for i in range(len(rank)):
         mirisyuu_list.append(data_all.columns[rank[i][0]])
      # print(mirisyuu_list)
         
      suisennkamoku = []#情報推薦する科目一覧
      #とりあえず必修科目と予測評価値が3以上の科目は推薦リストに追加
      for i in range(len(rank)): 
         #nondel_data_all.iloc[0,rank[i][0]] == 1 は必選別で１のもの（必修の科目）
         if nondel_data_all.iloc[0,rank[i][0]] == 1:
            suisennkamoku.append(mirisyuu_list[i])
         elif rank[i][1] >= 3:
            suisennkamoku.append(mirisyuu_list[i])
         else:
            pass

      #推薦科目として提示した科目を未履修リストから削除
      for i in range(len(suisennkamoku)):
         mirisyuu_list.remove(suisennkamoku[i])    

      #落胆した科目を未履修リストの最後尾に追加
      for i in range(len(data_all.columns)):
         #ここは落単した科目を mirisyuu_listに追加する
         if data_all.iloc[target_user_index,i] == 0:
            mirisyuu_list.append(data_all.columns[i])

      # 取得済み or 推薦済み の科目に0が入った配列
      for i in range(len(suisennkamoku)):
         data_train_user = data_train_user.replace({f'{suisennkamoku[i]}':{1:0}})
      
      all_sum=tannisyutoku0A(zeroA_sum, zeroA, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku0B(zeroB_sum, zeroB, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku0C(zeroC_sum, zeroC, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku0D(zeroD_sum, zeroD, data_all,rank, suisennkamoku, nondel_data_all ,all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku1A(itiA_sum, itiA, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku1B(itiB_sum, itiB, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku1C(itiC_sum, itiC, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku2A(niA_sum, niA, data_all, rank, suisennkamoku,nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku2B(niB_sum, niB, data_all, rank, suisennkamoku,nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku3A(sannA_sum, sannA, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku4A(yonnA_sum, yonnB, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku4B(yonnB_sum, yonnB, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku5A(goA_sum, goA, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku5B(goB_sum, goB, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku5C(goC_sum, goC, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku6A(rokuA_sum, rokuA, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku6B(rokuB_sum, rokuB, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku6C(rokuC_sum, rokuC, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku6D(rokuD_sum, rokuD, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku6E(rokuE_sum, rokuE, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)
      all_sum=tannisyutoku6F(rokuF_sum, rokuF, data_all, rank, suisennkamoku, nondel_data_all, all_sum, df4, mirisyuu_list)

      #推薦科目として提示した科目を未履修リストから削除
      for i in range(len(suisennkamoku)):
         try:
            mirisyuu_list.remove(suisennkamoku[i])
         except ValueError:
            i += 1
         #print(mirisyuu_list)

      #取得済みor推薦済みの科目に0が入った配列
      for i in range(len(suisennkamoku)):
         data_train_user = data_train_user.replace({f'{suisennkamoku[i]}':{1:0}})

      #この時点で取得予定単位数が卒業要件単位を満たしていなければ,suisennkamokuにmirisyuu_listを追加していく（上から）
      # それを，all_sum が all_all を超えるまで続ける
      if all_sum < all_all:
         i = 0
         while all_sum < all_all:
            suisennkamoku.append(mirisyuu_list[i])
            all_sum += nondel_data_all.iloc[2,data_all.columns.get_loc(f'{mirisyuu_list[i]}')]
            i += 1

      suisenn_10 = []
      suisenn_11 = []
      suisenn_20 = []
      suisenn_21 = []
      suisenn_30 = []
      suisenn_31 = []
      suisenn_40 = []
      
      for i in range(len(suisennkamoku)):
         # suisennkamokuの科目の配当学年が 10 のとき，suisenn_10 に suisennkamoku の科目を追加する
         if nondel_data_all.iloc[1,data_all.columns.get_loc(f'{suisennkamoku[i]}')] == 10:
            suisenn_10.append(suisennkamoku[i])
         # suisennkamokuの科目の配当学年が 11 のとき，suisenn_11 に suisennkamoku の科目を追加する
         elif nondel_data_all.iloc[1,data_all.columns.get_loc(f'{suisennkamoku[i]}')] == 11:
            suisenn_11.append(suisennkamoku[i])
         # suisennkamokuの科目の配当学年が 20 のとき，suisenn_20 に suisennkamoku の科目を追加する
         elif nondel_data_all.iloc[1,data_all.columns.get_loc(f'{suisennkamoku[i]}')] == 20:
            suisenn_20.append(suisennkamoku[i])
         # suisennkamokuの科目の配当学年が 21 のとき，suisenn_21 に suisennkamoku の科目を追加する
         elif nondel_data_all.iloc[1,data_all.columns.get_loc(f'{suisennkamoku[i]}')] == 21:
            suisenn_21.append(suisennkamoku[i])
         # suisennkamokuの科目の配当学年が 30 のとき，suisenn_30 に suisennkamoku の科目を追加する
         elif nondel_data_all.iloc[1,data_all.columns.get_loc(f'{suisennkamoku[i]}')] == 30:
            suisenn_30.append(suisennkamoku[i])
         # suisennkamokuの科目の配当学年が 31 のとき，suisenn_31 に suisennkamoku の科目を追加する
         elif nondel_data_all.iloc[1,data_all.columns.get_loc(f'{suisennkamoku[i]}')] == 31:
            suisenn_31.append(suisennkamoku[i])
         # suisennkamokuの科目の配当学年が 40 のとき，suisenn_40 に suisennkamoku の科目を追加する
         elif nondel_data_all.iloc[1,data_all.columns.get_loc(f'{suisennkamoku[i]}')] == 40:
            suisenn_40.append(suisennkamoku[i])
         else:
            pass

      # list型
      suisenn_all = suisenn_10 + suisenn_11 + suisenn_20 + suisenn_21 + suisenn_30 +suisenn_31 + suisenn_40
      print(len(suisenn_all))
      # list → データフレーム
    #   suisenn_all_df = pd.DataFrame(suisenn_10 + suisenn_11 + suisenn_20 + suisenn_21 + suisenn_30 +suisenn_31 + suisenn_40)
            
      suisenn_all_url = []
      suisenn_all_name  = []

      for i in range(len(suisenn_all)):
         if suisenn_all[i] == ('IoTシステムデザイン'):
            suisenn_all_name.append('IoTシステムデザイン')
            suisenn_all_url.append('IoTsystem')
            
         elif suisenn_all[i] == ('IoTプログラミング'):
            suisenn_all_name.append('IoTプログラミング')
            suisenn_all_url.append('iot_prog')
            
         elif suisenn_all[i] == ('アルゴリズムとデータ構造'):
            suisenn_all_name.append('アルゴリズムとデータ構造')
            suisenn_all_url.append('alg_data')
            
         elif suisenn_all[i] == ('インターンシップA'):
            suisenn_all_name.append('インターンシップA')
            suisenn_all_url.append('interA')
            
         elif suisenn_all[i] == ('インターンシップB'):
            suisenn_all_name.append('インターンシップB')
            suisenn_all_url.append('interB')

         elif suisenn_all[i] == ('オペレーションズ・リサーチ'):
            suisenn_all_name.append('オペレーションズ・リサーチ')
            suisenn_all_url.append('opera')
            
         elif suisenn_all[i] == ('オペレーティングシステム'):
            suisenn_all_name.append('オペレーティングシステム')
            suisenn_all_url.append('ope_sys')
            
         elif suisenn_all[i] == ('キャリア形成論'):
            suisenn_all_name.append('キャリア形成論')
            suisenn_all_url.append('career')
            
         elif suisenn_all[i] == ('コミュニケーションの社会学'):
            suisenn_all_name.append('コミュニケーションの社会学')
            suisenn_all_url.append('com_soc')
            
         elif suisenn_all[i] == ('コミュニケーション論'):
            suisenn_all_name.append('コミュニケーション論')
            suisenn_all_url.append('com_logi')
            
         elif suisenn_all[i] == ('コンパイラ'):
            suisenn_all_name.append('コンパイラ')
            suisenn_all_url.append('Compiler')
            
         elif suisenn_all[i] == ('コンピュータアーキテクチャ'):
            suisenn_all_name.append('コンピュータアーキテクチャ')
            suisenn_all_url.append('com_archi')
            
         elif suisenn_all[i] == ('コンピュータネットワーク'):
            suisenn_all_name.append('コンピュータネットワーク')
            suisenn_all_url.append('com_net')
            
         elif suisenn_all[i] == ('コンピュータ基礎'):
            suisenn_all_name.append('コンピュータ基礎')
            suisenn_all_url.append('com_base')
            
         elif suisenn_all[i] == ('ソフトウェア工学'):
            suisenn_all_name.append('ソフトウェア工学')
            suisenn_all_url.append('soft_engi')
            
         elif suisenn_all[i] == ('ディジタル信号処理'):
            suisenn_all_name.append('ディジタル信号処理')
            suisenn_all_url.append('DSP')
            
         elif suisenn_all[i] == ('データベースとデータ処理'):
            suisenn_all_name.append('データベースとデータ処理')
            suisenn_all_url.append('DB_DP')
            
         elif suisenn_all[i] == ('ドイツ語１'):
            suisenn_all_name.append('ドイツ語１')
            suisenn_all_url.append('German1_')
            
         elif suisenn_all[i] == ('ドイツ語２'):
            suisenn_all_name.append('ドイツ語２')
            suisenn_all_url.append('German2_')
            
         elif suisenn_all[i] == ('トピックゼミ１'):
            suisenn_all_name.append('トピックゼミ１')
            suisenn_all_url.append('topic_semi1_')
            
         elif suisenn_all[i] == ('トピックゼミ２'):
            suisenn_all_name.append('トピックゼミ２')
            suisenn_all_url.append('topic_semi2_')
            
         elif suisenn_all[i] == ('ヒューマンインタフェース'):
            suisenn_all_name.append('ヒューマンインタフェース')
            suisenn_all_url.append('hum_inter')
            
         elif suisenn_all[i] == ('フーリエ解析学'):
            suisenn_all_name.append('フーリエ解析学')
            suisenn_all_url.append('fourier')
            
         elif suisenn_all[i] == ('プレゼンテーション演習'):
            suisenn_all_name.append('プレゼンテーション演習')
            suisenn_all_url.append('presen_info')
            
         elif suisenn_all[i] == ('プログラミング１'):
            suisenn_all_name.append('プログラミング１')
            suisenn_all_url.append('programming1_')
            
         elif suisenn_all[i] == ('プログラミング演習１'):
            suisenn_all_name.append('プログラミング演習１')
            suisenn_all_url.append('prog_exe1_')
            
         elif suisenn_all[i] == ('プログラミング２'):
            suisenn_all_name.append('プログラミング２')
            suisenn_all_url.append('programming2_')
            
         elif suisenn_all[i] == ('プログラミング演習２'):
            suisenn_all_name.append('プログラミング演習２')
            suisenn_all_url.append('prog_exe2_')
            
         elif suisenn_all[i] == ('プログラミング３'):
            suisenn_all_name.append('プログラミング３')
            suisenn_all_url.append('programming3_')
            
         elif suisenn_all[i] == ('プログラミング演習３'):
            suisenn_all_name.append('プログラミング演習３')
            suisenn_all_url.append('prog_exe3_')
            
         elif suisenn_all[i] == ('プログラミング言語'):
            suisenn_all_name.append('プログラミング言語')
            suisenn_all_url.append('prog_lan')
            
         elif suisenn_all[i] == ('英語基礎１'):
            suisenn_all_name.append('英語基礎１')
            suisenn_all_url.append('english_base1_')
            
         elif suisenn_all[i] == ('英語基礎２'):
            suisenn_all_name.append('英語基礎２')
            suisenn_all_url.append('english_base2_')
            
         elif suisenn_all[i] == ('英語基礎３'):
            suisenn_all_name.append('英語基礎３')
            suisenn_all_url.append('english_base3_')
            
         elif suisenn_all[i] == ('英語基礎４'):
            suisenn_all_name.append('英語基礎４')
            suisenn_all_url.append('english_base4_')
            
         elif suisenn_all[i] == ('英語特別演習１'):
            suisenn_all_name.append('英語特別演習１')
            suisenn_all_url.append('spe_english1_')
            
         elif suisenn_all[i] == ('英語特別演習２'):
            suisenn_all_name.append('英語特別演習２')
            suisenn_all_url.append('spe_english2_')
            
         elif suisenn_all[i] == ('英語特別演習３'):
            suisenn_all_name.append('英語特別演習３')
            suisenn_all_url.append('spe_english3_')
            
         elif suisenn_all[i] == ('英語特別演習４'):
            suisenn_all_name.append('英語特別演習４')
            suisenn_all_url.append('spe_english4_')
            
         elif suisenn_all[i] == ('化学１'):
            suisenn_all_name.append('化学１')
            suisenn_all_url.append('chemi1_')
            
         elif suisenn_all[i] == ('化学２'):
            suisenn_all_name.append('化学２')
            suisenn_all_url.append('chemi2_')
            
         elif suisenn_all[i] == ('化学実験'):
            suisenn_all_name.append('化学実験')
            suisenn_all_url.append('chemi_exp')
            
         elif suisenn_all[i] == ('科学技術と社会'):
            suisenn_all_name.append('科学技術と社会')
            suisenn_all_url.append('tech_soc')
            
         elif suisenn_all[i] == ('科学技術史'):
            suisenn_all_name.append('科学技術史')
            suisenn_all_url.append('history_sci_tech')
         
         elif suisenn_all[i] == ('画像処理基礎'):
            suisenn_all_name.append('画像処理基礎')
            suisenn_all_url.append('image_process')
            
         elif suisenn_all[i] == ('確率・統計学'):
            suisenn_all_name.append('確率・統計学')
            suisenn_all_url.append('Pro_Stat')
            
         elif suisenn_all[i] == ('環境論１'):
            suisenn_all_name.append('環境論１')
            suisenn_all_url.append('enviro1_')
            
         elif suisenn_all[i] == ('環境論２'):
            suisenn_all_name.append('環境論２')
            suisenn_all_url.append('enviro2_1st')
            
         elif suisenn_all[i] == ('企業経営概論'):
            suisenn_all_name.append('企業経営概論')
            suisenn_all_url.append('business')
            
         elif suisenn_all[i] == ('機械学習'):
            suisenn_all_name.append('機械学習')
            suisenn_all_url.append('machine_learning')
            
         elif suisenn_all[i] == ('技術英語'):
            suisenn_all_name.append('技術英語')
            suisenn_all_url.append('tech_eng_info')
            
         elif suisenn_all[i] == ('技術者倫理'):
            suisenn_all_name.append('技術者倫理')
            suisenn_all_url.append('engi_ethic_info')
            
         elif suisenn_all[i] == ('教養ゼミ１'):
            suisenn_all_name.append('教養ゼミ１')
            suisenn_all_url.append('edu_semi1_')
            
         elif suisenn_all[i] == ('教養ゼミ２'):
            suisenn_all_name.append('教養ゼミ２')
            suisenn_all_url.append('edu_semi2_')
            
         elif suisenn_all[i] == ('近現代史'):
            suisenn_all_name.append('近現代史')
            suisenn_all_url.append('modern_his')
            
         elif suisenn_all[i] == ('経済学１'):
            suisenn_all_name.append('経済学１')
            suisenn_all_url.append('economics1_1st')
            
         elif suisenn_all[i] == ('経済学２'):
            suisenn_all_name.append('経済学２')
            suisenn_all_url.append('economics2_')
            
         elif suisenn_all[i] == ('健康科学１'):
            suisenn_all_name.append('健康科学１')
            suisenn_all_url.append('health_sci1B')
            
         elif suisenn_all[i] == ('健康科学２'):
            suisenn_all_name.append('健康科学２')
            suisenn_all_url.append('health_sci2_')
            
         elif suisenn_all[i] == ('健康科学演習'):
            suisenn_all_name.append('健康科学演習')
            suisenn_all_url.append('health_sci_exe1st')
            
         elif suisenn_all[i] == ('国際関係論'):
            suisenn_all_name.append('国際関係論')
            suisenn_all_url.append('inter_rela')
            
         elif suisenn_all[i] == ('社会学１'):
            suisenn_all_name.append('社会学１')
            suisenn_all_url.append('sociology1_1st')
            
         elif suisenn_all[i] == ('社会学２'):
            suisenn_all_name.append('社会学２')
            suisenn_all_url.append('sociology2_')
            
         elif suisenn_all[i] == ('情報システムと地球環境'):
            suisenn_all_name.append('情報システムと地球環境')
            suisenn_all_url.append('info_global')
            
         elif suisenn_all[i] == ('情報システム工学概論'):
            suisenn_all_name.append('情報システム工学概論')
            suisenn_all_url.append('intro_info_sys')
            
         elif suisenn_all[i] == ('情報システム工学実験１'):
            suisenn_all_name.append('情報システム工学実験１')
            suisenn_all_url.append('info_sys_exp1_')
            
         elif suisenn_all[i] == ('情報システム工学実験２'):
            suisenn_all_name.append('情報システム工学実験２')
            suisenn_all_url.append('info_sys_exp2_')
            
         elif suisenn_all[i] == ('情報システム工学特別講義'):
            suisenn_all_name.append('情報システム工学特別講義')
            suisenn_all_url.append('special_info')
            
         elif suisenn_all[i] == ('情報数学１'):
            suisenn_all_name.append('情報数学１')
            suisenn_all_url.append('info_math1_')
            
         elif suisenn_all[i] == ('情報数学２'):
            suisenn_all_name.append('情報数学２')
            suisenn_all_url.append('info_math2_')
            
         elif suisenn_all[i] == ('情報理論'):
            suisenn_all_name.append('情報理論')
            suisenn_all_url.append('info_theo')
            
         elif suisenn_all[i] == ('心理学１'):
            suisenn_all_name.append('心理学１')
            suisenn_all_url.append('psycho1_1st')
            
         elif suisenn_all[i] == ('心理学２'):
            suisenn_all_name.append('心理学２')
            suisenn_all_url.append('psycho2_1st')
            
         elif suisenn_all[i] == ('数学１'):
            suisenn_all_name.append('数学１')
            suisenn_all_url.append('math1_')
            
         elif suisenn_all[i] == ('数学２'):
            suisenn_all_name.append('数学２')
            suisenn_all_url.append('math2_')
            
         elif suisenn_all[i] == ('数学演習'):
            suisenn_all_name.append('数学演習')
            suisenn_all_url.append('nume_ana')
            
         elif suisenn_all[i] == ('数値解析'):
            suisenn_all_name.append('数値解析')
            suisenn_all_url.append('detasyorikiso')
            
         elif suisenn_all[i] == ('生体情報工学'):
            suisenn_all_name.append('生体情報工学')
            suisenn_all_url.append('bioinfo')
            
         elif suisenn_all[i] == ('生物学'):
            suisenn_all_name.append('生物学')
            suisenn_all_url.append('biology')
            
         elif suisenn_all[i] == ('専門ゼミ'):
            suisenn_all_name.append('専門ゼミ')
            suisenn_all_url.append('spe_semi')
            
         elif suisenn_all[i] == ('線形代数１'):
            suisenn_all_name.append('線形代数１')
            suisenn_all_url.append('line_algebra1_')
            
         elif suisenn_all[i] == ('線形代数２'):
            suisenn_all_name.append('線形代数２')
            suisenn_all_url.append('line_a;gebra2_')
            
         elif suisenn_all[i] == ('組み込みシステム工学'):
            suisenn_all_name.append('組み込みシステム工学')
            suisenn_all_url.append('embed_syst_engi')
            
         elif suisenn_all[i] == ('総合英語１'):
            suisenn_all_name.append('総合英語１')
            suisenn_all_url.append('compre_eng1_')
            
         elif suisenn_all[i] == ('総合英語２'):
            suisenn_all_name.append('総合英語２')
            suisenn_all_url.append('compre_eng2_')
            
         elif suisenn_all[i] == ('総合英語３'):
            suisenn_all_name.append('総合英語３')
            suisenn_all_url.append('compre_eng3_')
            
         elif suisenn_all[i] == ('総合英語４'):
            suisenn_all_name.append('総合英語４')
            suisenn_all_url.append('compre_eng4_')
            
         elif suisenn_all[i] == ('卒業研究１'):
            suisenn_all_name.append('卒業研究１')
            suisenn_all_url.append('grad_rese1_')
            
         elif suisenn_all[i] == ('卒業研究２'):
            suisenn_all_name.append('卒業研究２')
            suisenn_all_url.append('grad_rese')
            
         elif suisenn_all[i] == ('待ち行列と性能解析'):
            suisenn_all_name.append('待ち行列と性能解析')
            suisenn_all_url.append('queueing')
            
         elif suisenn_all[i] == ('中国語１'):
            suisenn_all_name.append('中国語１')
            suisenn_all_url.append('china1')
            
         elif suisenn_all[i] == ('中国語２'):
            suisenn_all_name.append('中国語２')
            suisenn_all_url.append('china2')
            
         elif suisenn_all[i] == ('通信方式'):
            suisenn_all_name.append('通信方式')
            suisenn_all_url.append('commu_sys')
            
         elif suisenn_all[i] == ('哲学'):
            suisenn_all_name.append('哲学')
            suisenn_all_url.append('philo')
            
         elif suisenn_all[i] == ('電気回路'):
            suisenn_all_name.append('電気回路')
            suisenn_all_url.append('elec_circuit')
            
         elif suisenn_all[i] == ('電子回路'):
            suisenn_all_name.append('電子回路')
            suisenn_all_url.append('electron_circuit')
            
         elif suisenn_all[i] == ('日本語表現法・前期'):
            suisenn_all_name.append('日本語表現法・前期')
            suisenn_all_url.append('japan_express_1st')
            
         elif suisenn_all[i] == ('日本語表現法・後期'):
            suisenn_all_name.append('日本語表現法・後期')
            suisenn_all_url.append('japan_express_2st')
            
         elif suisenn_all[i] == ('日本国憲法'):
            suisenn_all_name.append('日本国憲法')
            suisenn_all_url.append('japan_const')
            
         elif suisenn_all[i] == ('比較文化学１'):
            suisenn_all_name.append('比較文化学１')
            suisenn_all_url.append('compare1_1st')
            
         elif suisenn_all[i] == ('比較文化学２'):
            suisenn_all_name.append('比較文化学２')
            suisenn_all_url.append('compare2_')
            
         elif suisenn_all[i] == ('微分方程式論'):
            suisenn_all_name.append('微分方程式論')
            suisenn_all_url.append('diff_equ')
            
         elif suisenn_all[i] == ('富山と日本海'):
            suisenn_all_name.append('富山と日本海')
            suisenn_all_url.append('toyama_japan')
            
         elif suisenn_all[i] == ('複素解析学'):
            suisenn_all_name.append('複素解析学')
            suisenn_all_url.append('complex_ana')
            
         elif suisenn_all[i] == ('物理学１'):
            suisenn_all_name.append('物理学１')
            suisenn_all_url.append('physic1_')
            
         elif suisenn_all[i] == ('物理学１演習'):
            suisenn_all_name.append('物理学１演習')
            suisenn_all_url.append('physic1_exe')
            
         elif suisenn_all[i] == ('物理学２'):
            suisenn_all_name.append('物理学２')
            suisenn_all_url.append('physic2_')
            
         elif suisenn_all[i] == ('物理実験・前期'):
            suisenn_all_name.append('物理実験・前期')
            suisenn_all_url.append('physic_exp1st')
            
         elif suisenn_all[i] == ('物理実験・後期'):
            suisenn_all_name.append('物理実験・後期')
            suisenn_all_url.append('physic_exp2st')
            
         elif suisenn_all[i] == ('文学１'):
            suisenn_all_name.append('文学１')
            suisenn_all_url.append('literature1_')
            
         elif suisenn_all[i] == ('文学２'):
            suisenn_all_name.append('文学２')
            suisenn_all_url.append('literature2_')
            
         elif suisenn_all[i] == ('法学１'):
            suisenn_all_name.append('法学１')
            suisenn_all_url.append('law1_1st')
            
         elif suisenn_all[i] == ('法学２'):
            suisenn_all_name.append('法学２')
            suisenn_all_url.append('law2_2grade')
            
         elif suisenn_all[i] == ('倫理学'):
            suisenn_all_name.append('倫理学')
            suisenn_all_url.append('ethics')
            
         elif suisenn_all[i] == ('論理回路応用'):
            suisenn_all_name.append('論理回路応用')
            suisenn_all_url.append('logic_circuit_app')
         
         elif suisenn_all[i] == ('論理回路基礎'):
            suisenn_all_name.append('論理回路基礎')
            suisenn_all_url.append('logic_circuit_base')
            
         else:
            pass

      # index.htmlに表示する部分を設定する
      data_html = user_data[user_data[0].isin([int(name)])]
      data_html.columns = data_kako.columns
      data_html = data_html.drop(data_html.columns[-1], axis=1)
      data_html = data_html.replace({-1:"履修なし", 0: "落単or不可", 1:"C", 2:"B", 3:"A", 4:"S"})
      user_T = data_html.T
      
      # df_Tには data.csvから対象のユーザのデータを変換し，転置したもの
      return render_template("index.html", name=name, data = user_T.to_html(header=None),\
                              suisenn_all_url = suisenn_all_url, suisenn_all_name = suisenn_all_name)
   else:
      return redirect(url_for('start'))



#######################################################################################################
#############################################IoTシステムデザイン########################################
#######################################################################################################
@app.route("/IoTsystem")
def IoTsystem():
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/IoTシステムデザイン/IoTsystem_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/IoTsystem01")
def IoTsystem01():
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/IoTシステムデザイン/IoTsystem01.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/IoTsystem01_Review',methods = ["post"])
def IoTsystem01_Review():
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTシステムデザイン/IoTsystem01.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/IoTsystem01_mihyouka_Review", methods=["POST"])
def IoTsystem01_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])  

    return render_template("/IoTシステムデザイン/IoTsystem01.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/IoTsystem01_video',methods =["post"])
def IoTsystem01_video():
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTシステムデザイン/IoTsystem01.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/IoTsystem01_mihyouka_video',methods =["post"])
def IoTsystem01_mihyouka_video():
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTシステムデザイン/IoTsystem01.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/IoTsystem02")
def IoTsystem02():
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/IoTシステムデザイン/IoTsystem02.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/IoTsystem02_Review',methods = ["post"])
def IoTsystem02_Review():
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    # Windows環境
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    # Linux環境
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTシステムデザイン/IoTsystem02.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/IoTsystem02_mihyouka_Review", methods=["POST"])
def IoTsystem02_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/IoTシステムデザイン/IoTsystem02.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/IoTsystem02_video',methods =["post"])
def IoTsystem02_video():
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTシステムデザイン/IoTsystem02.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/IoTsystem02_mihyouka_video',methods =["post"])
def IoTsystem02_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTシステムデザイン/IoTsystem02.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/IoTsystem03")
def IoTsystem03():
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/IoTシステムデザイン/IoTsystem03.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/IoTsystem03_Review',methods = ["post"])
def IoTsystem03_Review():
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTシステムデザイン/IoTsystem03.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/IoTsystem03_mihyouka_Review", methods=["POST"])
def IoTsystem03_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/IoTシステムデザイン/IoTsystem03.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/IoTsystem03_video',methods =["post"])
def IoTsystem03_video():
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTシステムデザイン/IoTsystem03.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/IoTsystem03_mihyouka_video',methods =["post"])
def IoTsystem03_mihyouka_video():
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTシステムデザイン/IoTsystem03.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/IoTsystem04")
def IoTsystem04():
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/IoTシステムデザイン/IoTsystem04.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/IoTsystem04_Review',methods = ["post"])
def IoTsystem04_Review():
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTシステムデザイン/IoTsystem04.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/IoTsystem04_mihyouka_Review", methods=["POST"])
def IoTsystem04_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/IoTシステムデザイン/IoTsystem04.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/IoTsystem04_video',methods =["post"])
def IoTsystem04_video():
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTシステムデザイン/IoTsystem04.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/IoTsystem04_mihyouka_video',methods =["post"])
def IoTsystem04_mihyouka_video():
    df_key = pd.read_csv("Kamoku/IoTシステムデザイン/IoTシステムデザイン.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTシステムデザイン/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTシステムデザイン/IoTsystem04.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )




#######################################################################################################
#############################################IoTプログラミング##########################################
#######################################################################################################
@app.route("/iot_prog")
def iot_prog():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/IoTプログラミング/iot_prog_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/iot_prog1")
def iot_prog1():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/IoTプログラミング/iot_prog1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/iot_prog1_Review',methods = ["post"])
def iot_prog1_Review():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/iot_prog1_mihyouka_Review", methods=["POST"])
def iot_prog1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/IoTプログラミング/iot_prog1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/iot_prog1_video',methods =["post"])
def iot_prog1_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/iot_prog1_mihyouka_video',methods =["post"])
def iot_prog1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/iot_prog2")
def iot_prog2():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/IoTプログラミング/iot_prog2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/iot_prog2_Review',methods = ["post"])
def iot_prog2_Review():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/iot_prog2_mihyouka_Review", methods=["POST"])
def iot_prog2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/IoTプログラミング/iot_prog2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/iot_prog2_video',methods =["post"])
def iot_prog2_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/iot_prog2_mihyouka_video',methods =["post"])
def iot_prog2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/iot_prog3")
def iot_prog3():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/IoTプログラミング/iot_prog3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/iot_prog3_Review',methods = ["post"])
def iot_prog3_Review():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/iot_prog3_mihyouka_Review", methods=["POST"])
def iot_prog3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/IoTプログラミング/iot_prog3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/iot_prog3_video',methods =["post"])
def iot_prog3_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/iot_prog3_mihyouka_video',methods =["post"])
def iot_prog3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/iot_prog4")
def iot_prog4():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/IoTプログラミング/iot_prog4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/iot_prog4_Review',methods = ["post"])
def iot_prog4_Review():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/iot_prog4_mihyouka_Review", methods=["POST"])
def iot_prog4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/IoTプログラミング/iot_prog4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/iot_prog4_video',methods =["post"])
def iot_prog4_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/iot_prog4_mihyouka_video',methods =["post"])
def iot_prog4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/iot_prog5")
def iot_prog5():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/IoTプログラミング/iot_prog5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/iot_prog5_Review',methods = ["post"])
def iot_prog5_Review():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/iot_prog5_mihyouka_Review", methods=["POST"])
def iot_prog5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/IoTプログラミング/iot_prog5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/iot_prog5_video',methods =["post"])
def iot_prog5_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/iot_prog5_mihyouka_video',methods =["post"])
def iot_prog5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/iot_prog6")
def iot_prog6():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/IoTプログラミング/iot_prog6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/iot_prog6_Review',methods = ["post"])
def iot_prog6_Review():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/iot_prog6_mihyouka_Review", methods=["POST"])
def iot_prog6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/IoTプログラミング/iot_prog6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/iot_prog6_video',methods =["post"])
def iot_prog6_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/iot_prog6_mihyouka_video',methods =["post"])
def iot_prog6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/iot_prog7")
def iot_prog7():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/IoTプログラミング/iot_prog7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/iot_prog7_Review',methods = ["post"])
def iot_prog7_Review():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/iot_prog7_mihyouka_Review", methods=["POST"])
def iot_prog7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/IoTプログラミング/iot_prog7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/iot_prog7_video',methods =["post"])
def iot_prog7_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/iot_prog7_mihyouka_video',methods =["post"])
def iot_prog7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/iot_prog8")
def iot_prog8():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/IoTプログラミング/iot_prog8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/iot_prog8_Review',methods = ["post"])
def iot_prog8_Review():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/iot_prog8_mihyouka_Review", methods=["POST"])
def iot_prog8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/IoTプログラミング/iot_prog8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/iot_prog8_video',methods =["post"])
def iot_prog8_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/iot_prog8_mihyouka_video',methods =["post"])
def iot_prog8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/iot_prog9")
def iot_prog9():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/IoTプログラミング/iot_prog9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/iot_prog9_Review',methods = ["post"])
def iot_prog9_Review():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/iot_prog9_mihyouka_Review", methods=["POST"])
def iot_prog9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/IoTプログラミング/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/IoTプログラミング/iot_prog9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/iot_prog9_video',methods =["post"])
def iot_prog9_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/iot_prog9_mihyouka_video',methods =["post"])
def iot_prog9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/IoTプログラミング/IoTプログラミング.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/IoTプログラミング/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/IoTプログラミング/iot_prog9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



#######################################################################################################
#############################################アルゴリズムとデータ構造####################################
#######################################################################################################
@app.route("/alg_data")
def alg_data():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/アルゴリズムとデータ構造/alg_data_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/alg_data1")
def alg_data1():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/アルゴリズムとデータ構造/alg_data1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/alg_data1_Review',methods = ["post"])
def alg_data1_Review():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/alg_data1_mihyouka_Review", methods=["POST"])
def alg_data1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/アルゴリズムとデータ構造/alg_data1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/alg_data1_video',methods =["post"])
def alg_data1_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/alg_data1_mihyouka_video',methods =["post"])
def alg_data1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/alg_data2")
def alg_data2():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/アルゴリズムとデータ構造/alg_data2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/alg_data2_Review',methods = ["post"])
def alg_data2_Review():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/alg_data2_mihyouka_Review", methods=["POST"])
def alg_data2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/アルゴリズムとデータ構造/alg_data2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/alg_data2_video',methods =["post"])
def alg_data2_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/alg_data2_mihyouka_video',methods =["post"])
def alg_data2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/alg_data3")
def alg_data3():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/アルゴリズムとデータ構造/alg_data3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/alg_data3_Review',methods = ["post"])
def alg_data3_Review():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/alg_data3_mihyouka_Review", methods=["POST"])
def alg_data3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/アルゴリズムとデータ構造/alg_data3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/alg_data3_video',methods =["post"])
def alg_data3_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/alg_data3_mihyouka_video',methods =["post"])
def alg_data3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/alg_data4")
def alg_data4():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/アルゴリズムとデータ構造/alg_data4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/alg_data4_Review',methods = ["post"])
def alg_data4_Review():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/alg_data4_mihyouka_Review", methods=["POST"])
def alg_data4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/アルゴリズムとデータ構造/alg_data4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/alg_data4_video',methods =["post"])
def alg_data4_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/alg_data4_mihyouka_video',methods =["post"])
def alg_data4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/alg_data5")
def alg_data5():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/アルゴリズムとデータ構造/alg_data5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/alg_data5_Review',methods = ["post"])
def alg_data5_Review():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/alg_data5_mihyouka_Review", methods=["POST"])
def alg_data5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/アルゴリズムとデータ構造/alg_data5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/alg_data5_video',methods =["post"])
def alg_data5_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/alg_data5_mihyouka_video',methods =["post"])
def alg_data5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/alg_data6")
def alg_data6():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/アルゴリズムとデータ構造/alg_data6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/alg_data6_Review',methods = ["post"])
def alg_data6_Review():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/alg_data6_mihyouka_Review", methods=["POST"])
def alg_data6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/アルゴリズムとデータ構造/alg_data6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/alg_data6_video',methods =["post"])
def alg_data6_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/alg_data6_mihyouka_video',methods =["post"])
def alg_data6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/alg_data7")
def alg_data7():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/アルゴリズムとデータ構造/alg_data7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/alg_data7_Review',methods = ["post"])
def alg_data7_Review():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/alg_data7_mihyouka_Review", methods=["POST"])
def alg_data7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/アルゴリズムとデータ構造/alg_data7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/alg_data7_video',methods =["post"])
def alg_data7_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/alg_data7_mihyouka_video',methods =["post"])
def alg_data7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/alg_data8")
def alg_data8():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/アルゴリズムとデータ構造/alg_data8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/alg_data8_Review',methods = ["post"])
def alg_data8_Review():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/alg_data8_mihyouka_Review", methods=["POST"])
def alg_data8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/アルゴリズムとデータ構造/alg_data8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/alg_data8_video',methods =["post"])
def alg_data8_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/alg_data8_mihyouka_video',methods =["post"])
def alg_data8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/alg_data9")
def alg_data9():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/アルゴリズムとデータ構造/alg_data9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/alg_data9_Review',methods = ["post"])
def alg_data9_Review():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/alg_data9_mihyouka_Review", methods=["POST"])
def alg_data9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/アルゴリズムとデータ構造/alg_data9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/alg_data9_video',methods =["post"])
def alg_data9_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/alg_data9_mihyouka_video',methods =["post"])
def alg_data9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/alg_data10")
def alg_data10():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/アルゴリズムとデータ構造/alg_data10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/alg_data10_Review',methods = ["post"])
def alg_data10_Review():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/alg_data10_mihyouka_Review", methods=["POST"])
def alg_data10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/アルゴリズムとデータ構造/alg_data10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/alg_data10_video',methods =["post"])
def alg_data10_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/alg_data10_mihyouka_video',methods =["post"])
def alg_data10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/alg_data11")
def alg_data11():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/アルゴリズムとデータ構造/alg_data11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/alg_data11_Review',methods = ["post"])
def alg_data11_Review():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/alg_data11_mihyouka_Review", methods=["POST"])
def alg_data11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/アルゴリズムとデータ構造/alg_data11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/alg_data11_video',methods =["post"])
def alg_data11_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/alg_data11_mihyouka_video',methods =["post"])
def alg_data11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/alg_data12")
def alg_data12():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/アルゴリズムとデータ構造/alg_data12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/alg_data12_Review',methods = ["post"])
def alg_data12_Review():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/alg_data12_mihyouka_Review", methods=["POST"])
def alg_data12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/アルゴリズムとデータ構造/alg_data12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/alg_data12_video',methods =["post"])
def alg_data12_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/alg_data12_mihyouka_video',methods =["post"])
def alg_data12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/alg_data13")
def alg_data13():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/アルゴリズムとデータ構造/alg_data13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/alg_data13_Review',methods = ["post"])
def alg_data13_Review():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/alg_data13_mihyouka_Review", methods=["POST"])
def alg_data13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/アルゴリズムとデータ構造/alg_data13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/alg_data13_video',methods =["post"])
def alg_data13_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/alg_data13_mihyouka_video',methods =["post"])
def alg_data13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/alg_data14")
def alg_data14():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/アルゴリズムとデータ構造/alg_data14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/alg_data14_Review',methods = ["post"])
def alg_data14_Review():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/alg_data14_mihyouka_Review", methods=["POST"])
def alg_data14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/アルゴリズムとデータ構造/alg_data14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/alg_data14_video',methods =["post"])
def alg_data14_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/alg_data14_mihyouka_video',methods =["post"])
def alg_data14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/alg_data15")
def alg_data15():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/アルゴリズムとデータ構造/alg_data15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/alg_data15_Review',methods = ["post"])
def alg_data15_Review():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/alg_data15_mihyouka_Review", methods=["POST"])
def alg_data15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/アルゴリズムとデータ構造/alg_data15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/alg_data15_video',methods =["post"])
def alg_data15_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/alg_data15_mihyouka_video',methods =["post"])
def alg_data15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/アルゴリズムとデータ構造/アルゴリズムとデータ構造.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/アルゴリズムとデータ構造/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/アルゴリズムとデータ構造/alg_data15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


#######################################################################################################
#############################################インターンシップA（電子・情報）##############################
#######################################################################################################
@app.route("/interA")
def interA():
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/インターンシップA（電子・情報）/interA_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/interA1")
def interA1():
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/インターンシップA（電子・情報）/interA1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/interA1_Review',methods = ["post"])
def interA1_Review():
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップA（電子・情報）/interA1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/interA1_mihyouka_Review", methods=["POST"])
def interA1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/インターンシップA（電子・情報）/interA1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/interA1_video',methods =["post"])
def interA1_video():
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップA（電子・情報）/interA1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/interA1_mihyouka_video',methods =["post"])
def interA1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップA（電子・情報）/interA1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/interA2")
def interA2():
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/インターンシップA（電子・情報）/interA2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/interA2_Review',methods = ["post"])
def interA2_Review():
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップA（電子・情報）/interA2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/interA2_mihyouka_Review", methods=["POST"])
def interA2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/インターンシップA（電子・情報）/interA2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/interA2_video',methods =["post"])
def interA2_video():
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップA（電子・情報）/interA2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/interA2_mihyouka_video',methods =["post"])
def interA2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップA（電子・情報）/interA2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/interA3")
def interA3():
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/インターンシップA（電子・情報）/interA3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/interA3_Review',methods = ["post"])
def interA3_Review():
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップA（電子・情報）/interA3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/interA3_mihyouka_Review", methods=["POST"])
def interA3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/インターンシップA（電子・情報）/interA3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/interA3_video',methods =["post"])
def interA3_video():
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップA（電子・情報）/interA3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/interA3_mihyouka_video',methods =["post"])
def interA3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップA（電子・情報）/interA3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/interA4")
def interA4():
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/インターンシップA（電子・情報）/interA4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/interA4_Review',methods = ["post"])
def interA4_Review():
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップA（電子・情報）/interA4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/interA4_mihyouka_Review", methods=["POST"])
def interA4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/インターンシップA（電子・情報）/interA4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/interA4_video',methods =["post"])
def interA4_video():
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップA（電子・情報）/interA4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/interA4_mihyouka_video',methods =["post"])
def interA4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/インターンシップA（電子・情報）/インターンシップA（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップA（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップA（電子・情報）/interA4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


#######################################################################################################
#############################################インターンシップＢ（電子・情報）##############################
#######################################################################################################
@app.route("/interB")
def interB():
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/インターンシップＢ（電子・情報）/interB_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/interB1")
def interB1():
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/インターンシップＢ（電子・情報）/interB1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/interB1_Review',methods = ["post"])
def interB1_Review():
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップＢ（電子・情報）/interB1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/interB1_mihyouka_Review", methods=["POST"])
def interB1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/インターンシップＢ（電子・情報）/interB1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/interB1_video',methods =["post"])
def interB1_video():
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップＢ（電子・情報）/interB1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/interB1_mihyouka_video',methods =["post"])
def interB1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップＢ（電子・情報）/interB1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/interB2")
def interB2():
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/インターンシップＢ（電子・情報）/interB2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/interB2_Review',methods = ["post"])
def interB2_Review():
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップＢ（電子・情報）/interB2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/interB2_mihyouka_Review", methods=["POST"])
def interB2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/インターンシップＢ（電子・情報）/interB2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/interB2_video',methods =["post"])
def interB2_video():
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップＢ（電子・情報）/interB2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/interB2_mihyouka_video',methods =["post"])
def interB2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップＢ（電子・情報）/interB2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/interB3")
def interB3():
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/インターンシップＢ（電子・情報）/interB3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/interB3_Review',methods = ["post"])
def interB3_Review():
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップＢ（電子・情報）/interB3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/interB3_mihyouka_Review", methods=["POST"])
def interB3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/インターンシップＢ（電子・情報）/interB3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/interB3_video',methods =["post"])
def interB3_video():
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップＢ（電子・情報）/interB3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/interB3_mihyouka_video',methods =["post"])
def interB3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップＢ（電子・情報）/interB3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/interB4")
def interB4():
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/インターンシップＢ（電子・情報）/interB4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/interB4_Review',methods = ["post"])
def interB4_Review():
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップＢ（電子・情報）/interB4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/interB4_mihyouka_Review", methods=["POST"])
def interB4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/インターンシップＢ（電子・情報）/interB4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/interB4_video',methods =["post"])
def interB4_video():
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップＢ（電子・情報）/interB4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/interB4_mihyouka_video',methods =["post"])
def interB4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/インターンシップＢ（電子・情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/インターンシップＢ（電子・情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/インターンシップＢ（電子・情報）/interB4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


#######################################################################################################
#############################################オペレーションズ・リサーチ##################################
#######################################################################################################
@app.route("/opera")
def opera():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/オペレーションズ・リサーチ/opera_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/opera1")
def opera1():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーションズ・リサーチ/opera1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/opera1_Review',methods = ["post"])
def opera1_Review():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/opera1_mihyouka_Review", methods=["POST"])
def opera1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーションズ・リサーチ/opera1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/opera1_video',methods =["post"])
def opera1_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/opera1_mihyouka_video',methods =["post"])
def opera1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/opera2")
def opera2():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーションズ・リサーチ/opera2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/opera2_Review',methods = ["post"])
def opera2_Review():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/opera2_mihyouka_Review", methods=["POST"])
def opera2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーションズ・リサーチ/opera2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/opera2_video',methods =["post"])
def opera2_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/opera2_mihyouka_video',methods =["post"])
def opera2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/opera3")
def opera3():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーションズ・リサーチ/opera3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/opera3_Review',methods = ["post"])
def opera3_Review():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/opera3_mihyouka_Review", methods=["POST"])
def opera3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーションズ・リサーチ/opera3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/opera3_video',methods =["post"])
def opera3_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/opera3_mihyouka_video',methods =["post"])
def opera3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/opera4")
def opera4():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーションズ・リサーチ/opera4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/opera4_Review',methods = ["post"])
def opera4_Review():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/opera4_mihyouka_Review", methods=["POST"])
def opera4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーションズ・リサーチ/opera4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/opera4_video',methods =["post"])
def opera4_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/opera4_mihyouka_video',methods =["post"])
def opera4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/opera5")
def opera5():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーションズ・リサーチ/opera5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/opera5_Review',methods = ["post"])
def opera5_Review():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/opera5_mihyouka_Review", methods=["POST"])
def opera5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーションズ・リサーチ/opera5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/opera5_video',methods =["post"])
def opera5_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/opera5_mihyouka_video',methods =["post"])
def opera5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/opera6")
def opera6():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーションズ・リサーチ/opera6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/opera6_Review',methods = ["post"])
def opera6_Review():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/opera6_mihyouka_Review", methods=["POST"])
def opera6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーションズ・リサーチ/opera6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/opera6_video',methods =["post"])
def opera6_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/opera6_mihyouka_video',methods =["post"])
def opera6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/opera7")
def opera7():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーションズ・リサーチ/opera7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/opera7_Review',methods = ["post"])
def opera7_Review():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/opera7_mihyouka_Review", methods=["POST"])
def opera7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーションズ・リサーチ/opera7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/opera7_video',methods =["post"])
def opera7_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/opera7_mihyouka_video',methods =["post"])
def opera7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/opera8")
def opera8():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーションズ・リサーチ/opera8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/opera8_Review',methods = ["post"])
def opera8_Review():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/opera8_mihyouka_Review", methods=["POST"])
def opera8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーションズ・リサーチ/opera8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/opera8_video',methods =["post"])
def opera8_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/opera8_mihyouka_video',methods =["post"])
def opera8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/opera9")
def opera9():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーションズ・リサーチ/opera9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/opera9_Review',methods = ["post"])
def opera9_Review():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/opera9_mihyouka_Review", methods=["POST"])
def opera9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーションズ・リサーチ/opera9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/opera9_video',methods =["post"])
def opera9_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/opera9_mihyouka_video',methods =["post"])
def opera9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/opera10")
def opera10():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーションズ・リサーチ/opera10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/opera10_Review',methods = ["post"])
def opera10_Review():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/opera10_mihyouka_Review", methods=["POST"])
def opera10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーションズ・リサーチ/opera10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/opera10_video',methods =["post"])
def opera10_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/opera10_mihyouka_video',methods =["post"])
def opera10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/opera11")
def opera11():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーションズ・リサーチ/opera11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/opera11_Review',methods = ["post"])
def opera11_Review():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/opera11_mihyouka_Review", methods=["POST"])
def opera11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーションズ・リサーチ/opera11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/opera11_video',methods =["post"])
def opera11_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/opera11_mihyouka_video',methods =["post"])
def opera11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/opera12")
def opera12():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーションズ・リサーチ/opera12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/opera12_Review',methods = ["post"])
def opera12_Review():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/opera12_mihyouka_Review", methods=["POST"])
def opera12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーションズ・リサーチ/opera12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/opera12_video',methods =["post"])
def opera12_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/opera12_mihyouka_video',methods =["post"])
def opera12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/opera13")
def opera13():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーションズ・リサーチ/opera13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/opera13_Review',methods = ["post"])
def opera13_Review():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/opera13_mihyouka_Review", methods=["POST"])
def opera13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーションズ・リサーチ/opera13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/opera13_video',methods =["post"])
def opera13_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/opera13_mihyouka_video',methods =["post"])
def opera13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/opera14")
def opera14():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーションズ・リサーチ/opera14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/opera14_Review',methods = ["post"])
def opera14_Review():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/opera14_mihyouka_Review", methods=["POST"])
def opera14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーションズ・リサーチ/opera14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/opera14_video',methods =["post"])
def opera14_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/opera14_mihyouka_video',methods =["post"])
def opera14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/opera15")
def opera15():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーションズ・リサーチ/opera15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/opera15_Review',methods = ["post"])
def opera15_Review():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/opera15_mihyouka_Review", methods=["POST"])
def opera15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーションズ・リサーチ/opera15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/opera15_video',methods =["post"])
def opera15_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/opera15_mihyouka_video',methods =["post"])
def opera15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーションズ・リサーチ/オペレーションズ・リサーチ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーションズ・リサーチ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーションズ・リサーチ/opera15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


#######################################################################################################
#############################################オペレーティングシステム####################################
#######################################################################################################
@app.route("/ope_sys")
def ope_sys():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/オペレーティングシステム/ope_sys_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/ope_sys1")
def ope_sys1():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーティングシステム/ope_sys1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/ope_sys1_Review',methods = ["post"])
def ope_sys1_Review():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/ope_sys1_mihyouka_Review", methods=["POST"])
def ope_sys1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーティングシステム/ope_sys1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/ope_sys1_video',methods =["post"])
def ope_sys1_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/ope_sys1_mihyouka_video',methods =["post"])
def ope_sys1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/ope_sys2")
def ope_sys2():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーティングシステム/ope_sys2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/ope_sys2_Review',methods = ["post"])
def ope_sys2_Review():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/ope_sys2_mihyouka_Review", methods=["POST"])
def ope_sys2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーティングシステム/ope_sys2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/ope_sys2_video',methods =["post"])
def ope_sys2_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/ope_sys2_mihyouka_video',methods =["post"])
def ope_sys2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/ope_sys3")
def ope_sys3():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーティングシステム/ope_sys3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/ope_sys3_Review',methods = ["post"])
def ope_sys3_Review():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/ope_sys3_mihyouka_Review", methods=["POST"])
def ope_sys3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーティングシステム/ope_sys3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/ope_sys3_video',methods =["post"])
def ope_sys3_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/ope_sys3_mihyouka_video',methods =["post"])
def ope_sys3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/ope_sys4")
def ope_sys4():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーティングシステム/ope_sys4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/ope_sys4_Review',methods = ["post"])
def ope_sys4_Review():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/ope_sys4_mihyouka_Review", methods=["POST"])
def ope_sys4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーティングシステム/ope_sys4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/ope_sys4_video',methods =["post"])
def ope_sys4_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/ope_sys4_mihyouka_video',methods =["post"])
def ope_sys4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/ope_sys5")
def ope_sys5():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーティングシステム/ope_sys5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/ope_sys5_Review',methods = ["post"])
def ope_sys5_Review():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/ope_sys5_mihyouka_Review", methods=["POST"])
def ope_sys5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーティングシステム/ope_sys5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/ope_sys5_video',methods =["post"])
def ope_sys5_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/ope_sys5_mihyouka_video',methods =["post"])
def ope_sys5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/ope_sys6")
def ope_sys6():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーティングシステム/ope_sys6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/ope_sys6_Review',methods = ["post"])
def ope_sys6_Review():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/ope_sys6_mihyouka_Review", methods=["POST"])
def ope_sys6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーティングシステム/ope_sys6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/ope_sys6_video',methods =["post"])
def ope_sys6_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/ope_sys6_mihyouka_video',methods =["post"])
def ope_sys6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/ope_sys7")
def ope_sys7():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーティングシステム/ope_sys7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/ope_sys7_Review',methods = ["post"])
def ope_sys7_Review():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/ope_sys7_mihyouka_Review", methods=["POST"])
def ope_sys7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーティングシステム/ope_sys7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/ope_sys7_video',methods =["post"])
def ope_sys7_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/ope_sys7_mihyouka_video',methods =["post"])
def ope_sys7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/ope_sys8")
def ope_sys8():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーティングシステム/ope_sys8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/ope_sys8_Review',methods = ["post"])
def ope_sys8_Review():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/ope_sys8_mihyouka_Review", methods=["POST"])
def ope_sys8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーティングシステム/ope_sys8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/ope_sys8_video',methods =["post"])
def ope_sys8_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/ope_sys8_mihyouka_video',methods =["post"])
def ope_sys8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/ope_sys9")
def ope_sys9():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーティングシステム/ope_sys9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/ope_sys9_Review',methods = ["post"])
def ope_sys9_Review():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/ope_sys9_mihyouka_Review", methods=["POST"])
def ope_sys9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーティングシステム/ope_sys9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/ope_sys9_video',methods =["post"])
def ope_sys9_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/ope_sys9_mihyouka_video',methods =["post"])
def ope_sys9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/ope_sys10")
def ope_sys10():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/オペレーティングシステム/ope_sys10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/ope_sys10_Review',methods = ["post"])
def ope_sys10_Review():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/ope_sys10_mihyouka_Review", methods=["POST"])
def ope_sys10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/オペレーティングシステム/ope_sys10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/ope_sys10_video',methods =["post"])
def ope_sys10_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/ope_sys10_mihyouka_video',methods =["post"])
def ope_sys10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/オペレーティングシステム/オペレーティングシステム.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/オペレーティングシステム/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/オペレーティングシステム/ope_sys10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


####################################################################################################
#############################################キャリア形成論##########################################
####################################################################################################
@app.route("/career")
def career():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/キャリア形成論/career_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/career1")
def career1():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/キャリア形成論/career1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/career1_Review',methods = ["post"])
def career1_Review():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/キャリア形成論/career1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/career1_mihyouka_Review", methods=["POST"])
def career1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/キャリア形成論/career1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/career1_video',methods =["post"])
def career1_video():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/キャリア形成論/career1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/career1_mihyouka_video',methods =["post"])
def career1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/キャリア形成論/career1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/career2")
def career2():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/キャリア形成論/career2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/career2_Review',methods = ["post"])
def career2_Review():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/キャリア形成論/career2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/career2_mihyouka_Review", methods=["POST"])
def career2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/キャリア形成論/career2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/career2_video',methods =["post"])
def career2_video():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/キャリア形成論/career2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/career2_mihyouka_video',methods =["post"])
def career2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/キャリア形成論/career2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/career3")
def career3():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/キャリア形成論/career3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/career3_Review',methods = ["post"])
def career3_Review():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/キャリア形成論/career3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/career3_mihyouka_Review", methods=["POST"])
def career3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/キャリア形成論/career3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/career3_video',methods =["post"])
def career3_video():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/キャリア形成論/career3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/career3_mihyouka_video',methods =["post"])
def career3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/キャリア形成論/career3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/career4")
def career4():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/キャリア形成論/career4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/career4_Review',methods = ["post"])
def career4_Review():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/キャリア形成論/career4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/career4_mihyouka_Review", methods=["POST"])
def career4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/キャリア形成論/career4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/career4_video',methods =["post"])
def career4_video():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/キャリア形成論/career4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/career4_mihyouka_video',methods =["post"])
def career4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/キャリア形成論/career4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/career5")
def career5():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/キャリア形成論/career5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/career5_Review',methods = ["post"])
def career5_Review():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/キャリア形成論/career5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/career5_mihyouka_Review", methods=["POST"])
def career5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/キャリア形成論/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/キャリア形成論/career5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/career5_video',methods =["post"])
def career5_video():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/キャリア形成論/career5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/career5_mihyouka_video',methods =["post"])
def career5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/キャリア形成論/キャリア形成論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/キャリア形成論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/キャリア形成論/career5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

####################################################################################################
#############################################コミュニケーションの社会学###############################
####################################################################################################
@app.route("/com_soc")
def com_soc():
    df_key = pd.read_csv("Kamoku/コミュニケーションの社会学/コミュニケーションの社会学.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/コミュニケーションの社会学/com_soc_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/com_soc1")
def com_soc1():
    df_key = pd.read_csv("Kamoku/コミュニケーションの社会学/コミュニケーションの社会学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コミュニケーションの社会学/com_soc1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_soc1_Review',methods = ["post"])
def com_soc1_Review():
    df_key = pd.read_csv("Kamoku/コミュニケーションの社会学/コミュニケーションの社会学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーションの社会学/com_soc1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_soc1_mihyouka_Review", methods=["POST"])
def com_soc1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コミュニケーションの社会学/コミュニケーションの社会学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コミュニケーションの社会学/com_soc1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_soc1_video',methods =["post"])
def com_soc1_video():
    df_key = pd.read_csv("Kamoku/コミュニケーションの社会学/コミュニケーションの社会学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーションの社会学/com_soc1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_soc1_mihyouka_video',methods =["post"])
def com_soc1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コミュニケーションの社会学/コミュニケーションの社会学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーションの社会学/com_soc1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/com_soc2")
def com_soc2():
    df_key = pd.read_csv("Kamoku/コミュニケーションの社会学/コミュニケーションの社会学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コミュニケーションの社会学/com_soc2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_soc2_Review',methods = ["post"])
def com_soc2_Review():
    df_key = pd.read_csv("Kamoku/コミュニケーションの社会学/コミュニケーションの社会学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーションの社会学/com_soc2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_soc2_mihyouka_Review", methods=["POST"])
def com_soc2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コミュニケーションの社会学/コミュニケーションの社会学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コミュニケーションの社会学/com_soc2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_soc2_video',methods =["post"])
def com_soc2_video():
    df_key = pd.read_csv("Kamoku/コミュニケーションの社会学/コミュニケーションの社会学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーションの社会学/com_soc2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_soc2_mihyouka_video',methods =["post"])
def com_soc2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーションの社会学/com_soc2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/com_soc3")
def com_soc3():
    df_key = pd.read_csv("Kamoku/コミュニケーションの社会学/コミュニケーションの社会学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コミュニケーションの社会学/com_soc3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_soc3_Review',methods = ["post"])
def com_soc3_Review():
    df_key = pd.read_csv("Kamoku/コミュニケーションの社会学/コミュニケーションの社会学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーションの社会学/com_soc3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_soc3_mihyouka_Review", methods=["POST"])
def com_soc3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コミュニケーションの社会学/コミュニケーションの社会学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コミュニケーションの社会学/com_soc3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_soc3_video',methods =["post"])
def com_soc3_video():
    df_key = pd.read_csv("Kamoku/コミュニケーションの社会学/コミュニケーションの社会学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーションの社会学/com_soc3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_soc3_mihyouka_video',methods =["post"])
def com_soc3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コミュニケーションの社会学/コミュニケーションの社会学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーションの社会学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーションの社会学/com_soc3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


####################################################################################################
#############################################コミュニケーション論#####################################
####################################################################################################
@app.route("/com_logi")
def com_logi():
    df_key = pd.read_csv("Kamoku/コミュニケーション論/コミュニケーション論.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/コミュニケーション論/com_logi_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/com_logi1")
def com_logi1():
    df_key = pd.read_csv("Kamoku/コミュニケーション論/コミュニケーション論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コミュニケーション論/com_logi1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_logi1_Review',methods = ["post"])
def com_logi1_Review():
    df_key = pd.read_csv("Kamoku/コミュニケーション論/コミュニケーション論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コミュニケーション論/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コミュニケーション論/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コミュニケーション論/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーション論/com_logi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_logi1_mihyouka_Review", methods=["POST"])
def com_logi1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コミュニケーション論/コミュニケーション論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コミュニケーション論/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コミュニケーション論/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コミュニケーション論/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コミュニケーション論/com_logi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_logi1_video',methods =["post"])
def com_logi1_video():
    df_key = pd.read_csv("Kamoku/コミュニケーション論/コミュニケーション論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーション論/com_logi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_logi1_mihyouka_video',methods =["post"])
def com_logi1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コミュニケーション論/コミュニケーション論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーション論/com_logi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/com_logi2")
def com_logi2():
    df_key = pd.read_csv("Kamoku/コミュニケーション論/コミュニケーション論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コミュニケーション論/com_logi2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_logi2_Review',methods = ["post"])
def com_logi2_Review():
    df_key = pd.read_csv("Kamoku/コミュニケーション論/コミュニケーション論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コミュニケーション論/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コミュニケーション論/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コミュニケーション論/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーション論/com_logi2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_logi2_mihyouka_Review", methods=["POST"])
def com_logi2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コミュニケーション論/コミュニケーション論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コミュニケーション論/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コミュニケーション論/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コミュニケーション論/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コミュニケーション論/com_logi2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_logi2_video',methods =["post"])
def com_logi2_video():
    df_key = pd.read_csv("Kamoku/コミュニケーション論/コミュニケーション論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーション論/com_logi2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_logi2_mihyouka_video',methods =["post"])
def com_logi2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーション論/com_logi2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/com_logi3")
def com_logi3():
    df_key = pd.read_csv("Kamoku/コミュニケーション論/コミュニケーション論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コミュニケーション論/com_logi3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_logi3_Review',methods = ["post"])
def com_logi3_Review():
    df_key = pd.read_csv("Kamoku/コミュニケーション論/コミュニケーション論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コミュニケーション論/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コミュニケーション論/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コミュニケーション論/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーション論/com_logi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_logi3_mihyouka_Review", methods=["POST"])
def com_logi3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コミュニケーション論/コミュニケーション論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コミュニケーション論/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コミュニケーション論/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コミュニケーション論/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コミュニケーション論/com_logi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_logi3_video',methods =["post"])
def com_logi3_video():
    df_key = pd.read_csv("Kamoku/コミュニケーション論/コミュニケーション論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーション論/com_logi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_logi3_mihyouka_video',methods =["post"])
def com_logi3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コミュニケーション論/コミュニケーション論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コミュニケーション論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コミュニケーション論/com_logi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


################################################################################################
#############################################コンパイラ##########################################
################################################################################################
@app.route("/Compiler")
def Compiler():
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/コンパイラ/Compiler_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/Compiler1")
def Compiler1():
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンパイラ/Compiler1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Compiler1_Review',methods = ["post"])
def Compiler1_Review():
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンパイラ/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンパイラ/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンパイラ/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンパイラ/Compiler1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Compiler1_mihyouka_Review", methods=["POST"])
def Compiler1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンパイラ/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンパイラ/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンパイラ/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンパイラ/Compiler1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Compiler1_video',methods =["post"])
def Compiler1_video():
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンパイラ/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンパイラ/Compiler1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Compiler1_mihyouka_video',methods =["post"])
def Compiler1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンパイラ/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンパイラ/Compiler1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/Compiler2")
def Compiler2():
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンパイラ/Compiler2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Compiler2_Review',methods = ["post"])
def Compiler2_Review():
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンパイラ/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンパイラ/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンパイラ/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンパイラ/Compiler2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Compiler2_mihyouka_Review", methods=["POST"])
def Compiler2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンパイラ/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンパイラ/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンパイラ/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンパイラ/Compiler2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Compiler2_video',methods =["post"])
def Compiler2_video():
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンパイラ/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンパイラ/Compiler2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Compiler2_mihyouka_video',methods =["post"])
def Compiler2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンパイラ/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンパイラ/Compiler2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/Compiler3")
def Compiler3():
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンパイラ/Compiler3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Compiler3_Review',methods = ["post"])
def Compiler3_Review():
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンパイラ/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンパイラ/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンパイラ/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンパイラ/Compiler3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Compiler3_mihyouka_Review", methods=["POST"])
def Compiler3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンパイラ/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンパイラ/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンパイラ/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンパイラ/Compiler3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Compiler3_video',methods =["post"])
def Compiler3_video():
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンパイラ/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンパイラ/Compiler3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Compiler3_mihyouka_video',methods =["post"])
def Compiler3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンパイラ/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンパイラ/Compiler3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/Compiler4")
def Compiler4():
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンパイラ/Compiler4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Compiler4_Review',methods = ["post"])
def Compiler4_Review():
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンパイラ/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンパイラ/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンパイラ/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンパイラ/Compiler4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Compiler4_mihyouka_Review", methods=["POST"])
def Compiler4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンパイラ/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンパイラ/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンパイラ/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンパイラ/Compiler4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Compiler4_video',methods =["post"])
def Compiler4_video():
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンパイラ/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンパイラ/Compiler4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Compiler4_mihyouka_video',methods =["post"])
def Compiler4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンパイラ/コンパイラ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンパイラ/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンパイラ/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンパイラ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンパイラ/Compiler4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################コンピュータアーキテクチャ###########################
################################################################################################
@app.route("/com_archi")
def com_archi():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/コンピュータアーキテクチャ/com_archi_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/com_archi1")
def com_archi1():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータアーキテクチャ/com_archi1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_archi1_Review',methods = ["post"])
def com_archi1_Review():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_archi1_mihyouka_Review", methods=["POST"])
def com_archi1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータアーキテクチャ/com_archi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_archi1_video',methods =["post"])
def com_archi1_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_archi1_mihyouka_video',methods =["post"])
def com_archi1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/com_archi2")
def com_archi2():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータアーキテクチャ/com_archi2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_archi2_Review',methods = ["post"])
def com_archi2_Review():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_archi2_mihyouka_Review", methods=["POST"])
def com_archi2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータアーキテクチャ/com_archi2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_archi2_video',methods =["post"])
def com_archi2_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_archi2_mihyouka_video',methods =["post"])
def com_archi2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/com_archi3")
def com_archi3():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータアーキテクチャ/com_archi3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_archi3_Review',methods = ["post"])
def com_archi3_Review():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_archi3_mihyouka_Review", methods=["POST"])
def com_archi3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータアーキテクチャ/com_archi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_archi3_video',methods =["post"])
def com_archi3_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_archi3_mihyouka_video',methods =["post"])
def com_archi3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/com_archi4")
def com_archi4():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータアーキテクチャ/com_archi4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_archi4_Review',methods = ["post"])
def com_archi4_Review():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_archi4_mihyouka_Review", methods=["POST"])
def com_archi4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータアーキテクチャ/com_archi4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_archi4_video',methods =["post"])
def com_archi4_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_archi4_mihyouka_video',methods =["post"])
def com_archi4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/com_archi5")
def com_archi5():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータアーキテクチャ/com_archi5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_archi5_Review',methods = ["post"])
def com_archi5_Review():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_archi5_mihyouka_Review", methods=["POST"])
def com_archi5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータアーキテクチャ/com_archi5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_archi5_video',methods =["post"])
def com_archi5_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_archi5_mihyouka_video',methods =["post"])
def com_archi5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/com_archi6")
def com_archi6():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータアーキテクチャ/com_archi6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_archi6_Review',methods = ["post"])
def com_archi6_Review():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_archi6_mihyouka_Review", methods=["POST"])
def com_archi6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータアーキテクチャ/com_archi6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_archi6_video',methods =["post"])
def com_archi6_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_archi6_mihyouka_video',methods =["post"])
def com_archi6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/com_archi7")
def com_archi7():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータアーキテクチャ/com_archi7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_archi7_Review',methods = ["post"])
def com_archi7_Review():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_archi7_mihyouka_Review", methods=["POST"])
def com_archi7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータアーキテクチャ/com_archi7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_archi7_video',methods =["post"])
def com_archi7_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_archi7_mihyouka_video',methods =["post"])
def com_archi7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/com_archi8")
def com_archi8():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータアーキテクチャ/com_archi8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_archi8_Review',methods = ["post"])
def com_archi8_Review():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_archi8_mihyouka_Review", methods=["POST"])
def com_archi8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータアーキテクチャ/com_archi8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_archi8_video',methods =["post"])
def com_archi8_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_archi8_mihyouka_video',methods =["post"])
def com_archi8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/com_archi9")
def com_archi9():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータアーキテクチャ/com_archi9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_archi9_Review',methods = ["post"])
def com_archi9_Review():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_archi9_mihyouka_Review", methods=["POST"])
def com_archi9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータアーキテクチャ/com_archi9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_archi9_video',methods =["post"])
def com_archi9_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_archi9_mihyouka_video',methods =["post"])
def com_archi9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/com_archi10")
def com_archi10():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータアーキテクチャ/com_archi10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_archi10_Review',methods = ["post"])
def com_archi10_Review():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_archi10_mihyouka_Review", methods=["POST"])
def com_archi10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータアーキテクチャ/com_archi10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_archi10_video',methods =["post"])
def com_archi10_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_archi10_mihyouka_video',methods =["post"])
def com_archi10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/com_archi11")
def com_archi11():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータアーキテクチャ/com_archi11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_archi11_Review',methods = ["post"])
def com_archi11_Review():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_archi11_mihyouka_Review", methods=["POST"])
def com_archi11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータアーキテクチャ/com_archi11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_archi11_video',methods =["post"])
def com_archi11_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_archi11_mihyouka_video',methods =["post"])
def com_archi11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/com_archi12")
def com_archi12():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータアーキテクチャ/com_archi12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_archi12_Review',methods = ["post"])
def com_archi12_Review():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_archi12_mihyouka_Review", methods=["POST"])
def com_archi12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータアーキテクチャ/com_archi12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_archi12_video',methods =["post"])
def com_archi12_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_archi12_mihyouka_video',methods =["post"])
def com_archi12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/com_archi13")
def com_archi13():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータアーキテクチャ/com_archi13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_archi13_Review',methods = ["post"])
def com_archi13_Review():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_archi13_mihyouka_Review", methods=["POST"])
def com_archi13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータアーキテクチャ/com_archi13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_archi13_video',methods =["post"])
def com_archi13_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_archi13_mihyouka_video',methods =["post"])
def com_archi13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/com_archi14")
def com_archi14():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータアーキテクチャ/com_archi14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_archi14_Review',methods = ["post"])
def com_archi14_Review():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_archi14_mihyouka_Review", methods=["POST"])
def com_archi14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータアーキテクチャ/com_archi14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_archi14_video',methods =["post"])
def com_archi14_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_archi14_mihyouka_video',methods =["post"])
def com_archi14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/com_archi15")
def com_archi15():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータアーキテクチャ/com_archi15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_archi15_Review',methods = ["post"])
def com_archi15_Review():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_archi15_mihyouka_Review", methods=["POST"])
def com_archi15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータアーキテクチャ/com_archi15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_archi15_video',methods =["post"])
def com_archi15_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_archi15_mihyouka_video',methods =["post"])
def com_archi15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータアーキテクチャ/コンピュータアーキテクチャ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータアーキテクチャ/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータアーキテクチャ/com_archi15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


################################################################################################
#############################################コンピュータネットワーク#############################
################################################################################################
@app.route("/com_net")
def com_net():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/コンピュータネットワーク/com_net_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/com_net1")
def com_net1():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータネットワーク/com_net1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_net1_Review',methods = ["post"])
def com_net1_Review():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_net1_mihyouka_Review", methods=["POST"])
def com_net1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータネットワーク/com_net1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_net1_video',methods =["post"])
def com_net1_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_net1_mihyouka_video',methods =["post"])
def com_net1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/com_net2")
def com_net2():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータネットワーク/com_net2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_net2_Review',methods = ["post"])
def com_net2_Review():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_net2_mihyouka_Review", methods=["POST"])
def com_net2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータネットワーク/com_net2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_net2_video',methods =["post"])
def com_net2_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_net2_mihyouka_video',methods =["post"])
def com_net2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/com_net3")
def com_net3():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータネットワーク/com_net3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_net3_Review',methods = ["post"])
def com_net3_Review():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_net3_mihyouka_Review", methods=["POST"])
def com_net3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータネットワーク/com_net3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_net3_video',methods =["post"])
def com_net3_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_net3_mihyouka_video',methods =["post"])
def com_net3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/com_net4")
def com_net4():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータネットワーク/com_net4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_net4_Review',methods = ["post"])
def com_net4_Review():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_net4_mihyouka_Review", methods=["POST"])
def com_net4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータネットワーク/com_net4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_net4_video',methods =["post"])
def com_net4_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_net4_mihyouka_video',methods =["post"])
def com_net4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/com_net5")
def com_net5():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータネットワーク/com_net5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_net5_Review',methods = ["post"])
def com_net5_Review():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_net5_mihyouka_Review", methods=["POST"])
def com_net5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータネットワーク/com_net5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_net5_video',methods =["post"])
def com_net5_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_net5_mihyouka_video',methods =["post"])
def com_net5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/com_net6")
def com_net6():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータネットワーク/com_net6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_net6_Review',methods = ["post"])
def com_net6_Review():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_net6_mihyouka_Review", methods=["POST"])
def com_net6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータネットワーク/com_net6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_net6_video',methods =["post"])
def com_net6_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_net6_mihyouka_video',methods =["post"])
def com_net6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/com_net7")
def com_net7():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータネットワーク/com_net7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_net7_Review',methods = ["post"])
def com_net7_Review():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_net7_mihyouka_Review", methods=["POST"])
def com_net7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータネットワーク/com_net7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_net7_video',methods =["post"])
def com_net7_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_net7_mihyouka_video',methods =["post"])
def com_net7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/com_net8")
def com_net8():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータネットワーク/com_net8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_net8_Review',methods = ["post"])
def com_net8_Review():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_net8_mihyouka_Review", methods=["POST"])
def com_net8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータネットワーク/com_net8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_net8_video',methods =["post"])
def com_net8_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_net8_mihyouka_video',methods =["post"])
def com_net8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/com_net9")
def com_net9():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータネットワーク/com_net9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_net9_Review',methods = ["post"])
def com_net9_Review():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_net9_mihyouka_Review", methods=["POST"])
def com_net9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータネットワーク/com_net9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_net9_video',methods =["post"])
def com_net9_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_net9_mihyouka_video',methods =["post"])
def com_net9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/com_net10")
def com_net10():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータネットワーク/com_net10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_net10_Review',methods = ["post"])
def com_net10_Review():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_net10_mihyouka_Review", methods=["POST"])
def com_net10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータネットワーク/com_net10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_net10_video',methods =["post"])
def com_net10_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_net10_mihyouka_video',methods =["post"])
def com_net10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/com_net11")
def com_net11():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータネットワーク/com_net11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_net11_Review',methods = ["post"])
def com_net11_Review():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_net11_mihyouka_Review", methods=["POST"])
def com_net11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータネットワーク/com_net11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_net11_video',methods =["post"])
def com_net11_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_net11_mihyouka_video',methods =["post"])
def com_net11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/com_net12")
def com_net12():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータネットワーク/com_net12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_net12_Review',methods = ["post"])
def com_net12_Review():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_net12_mihyouka_Review", methods=["POST"])
def com_net12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータネットワーク/com_net12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_net12_video',methods =["post"])
def com_net12_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_net12_mihyouka_video',methods =["post"])
def com_net12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/com_net13")
def com_net13():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータネットワーク/com_net13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_net13_Review',methods = ["post"])
def com_net13_Review():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_net13_mihyouka_Review", methods=["POST"])
def com_net13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータネットワーク/com_net13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_net13_video',methods =["post"])
def com_net13_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_net13_mihyouka_video',methods =["post"])
def com_net13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/com_net14")
def com_net14():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータネットワーク/com_net14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_net14_Review',methods = ["post"])
def com_net14_Review():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_net14_mihyouka_Review", methods=["POST"])
def com_net14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータネットワーク/com_net14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_net14_video',methods =["post"])
def com_net14_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_net14_mihyouka_video',methods =["post"])
def com_net14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/com_net15")
def com_net15():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータネットワーク/com_net15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_net15_Review',methods = ["post"])
def com_net15_Review():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_net15_mihyouka_Review", methods=["POST"])
def com_net15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータネットワーク/com_net15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_net15_video',methods =["post"])
def com_net15_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_net15_mihyouka_video',methods =["post"])
def com_net15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータネットワーク/コンピュータネットワーク.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータネットワーク/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータネットワーク/com_net15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


################################################################################################
#############################################コンピュータ基礎####################################
################################################################################################
@app.route("/com_base")
def com_base():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/コンピュータ基礎/com_base_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/com_base1")
def com_base1():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータ基礎/com_base1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_base1_Review',methods = ["post"])
def com_base1_Review():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_base1_mihyouka_Review", methods=["POST"])
def com_base1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータ基礎/com_base1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_base1_video',methods =["post"])
def com_base1_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_base1_mihyouka_video',methods =["post"])
def com_base1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/com_base2")
def com_base2():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータ基礎/com_base2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_base2_Review',methods = ["post"])
def com_base2_Review():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_base2_mihyouka_Review", methods=["POST"])
def com_base2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータ基礎/com_base2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_base2_video',methods =["post"])
def com_base2_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_base2_mihyouka_video',methods =["post"])
def com_base2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/com_base3")
def com_base3():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータ基礎/com_base3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_base3_Review',methods = ["post"])
def com_base3_Review():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_base3_mihyouka_Review", methods=["POST"])
def com_base3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータ基礎/com_base3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_base3_video',methods =["post"])
def com_base3_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_base3_mihyouka_video',methods =["post"])
def com_base3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/com_base4")
def com_base4():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータ基礎/com_base4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_base4_Review',methods = ["post"])
def com_base4_Review():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_base4_mihyouka_Review", methods=["POST"])
def com_base4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータ基礎/com_base4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_base4_video',methods =["post"])
def com_base4_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_base4_mihyouka_video',methods =["post"])
def com_base4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/com_base5")
def com_base5():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータ基礎/com_base5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_base5_Review',methods = ["post"])
def com_base5_Review():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_base5_mihyouka_Review", methods=["POST"])
def com_base5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータ基礎/com_base5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_base5_video',methods =["post"])
def com_base5_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_base5_mihyouka_video',methods =["post"])
def com_base5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/com_base6")
def com_base6():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータ基礎/com_base6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_base6_Review',methods = ["post"])
def com_base6_Review():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_base6_mihyouka_Review", methods=["POST"])
def com_base6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータ基礎/com_base6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_base6_video',methods =["post"])
def com_base6_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_base6_mihyouka_video',methods =["post"])
def com_base6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/com_base7")
def com_base7():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータ基礎/com_base7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_base7_Review',methods = ["post"])
def com_base7_Review():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_base7_mihyouka_Review", methods=["POST"])
def com_base7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータ基礎/com_base7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_base7_video',methods =["post"])
def com_base7_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_base7_mihyouka_video',methods =["post"])
def com_base7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/com_base8")
def com_base8():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータ基礎/com_base8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_base8_Review',methods = ["post"])
def com_base8_Review():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_base8_mihyouka_Review", methods=["POST"])
def com_base8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータ基礎/com_base8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_base8_video',methods =["post"])
def com_base8_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_base8_mihyouka_video',methods =["post"])
def com_base8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/com_base9")
def com_base9():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータ基礎/com_base9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_base9_Review',methods = ["post"])
def com_base9_Review():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_base9_mihyouka_Review", methods=["POST"])
def com_base9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータ基礎/com_base9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_base9_video',methods =["post"])
def com_base9_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_base9_mihyouka_video',methods =["post"])
def com_base9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/com_base10")
def com_base10():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータ基礎/com_base10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_base10_Review',methods = ["post"])
def com_base10_Review():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_base10_mihyouka_Review", methods=["POST"])
def com_base10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータ基礎/com_base10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_base10_video',methods =["post"])
def com_base10_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_base10_mihyouka_video',methods =["post"])
def com_base10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/com_base11")
def com_base11():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータ基礎/com_base11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_base11_Review',methods = ["post"])
def com_base11_Review():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_base11_mihyouka_Review", methods=["POST"])
def com_base11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータ基礎/com_base11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_base11_video',methods =["post"])
def com_base11_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_base11_mihyouka_video',methods =["post"])
def com_base11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/com_base12")
def com_base12():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータ基礎/com_base12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_base12_Review',methods = ["post"])
def com_base12_Review():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_base12_mihyouka_Review", methods=["POST"])
def com_base12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータ基礎/com_base12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_base12_video',methods =["post"])
def com_base12_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_base12_mihyouka_video',methods =["post"])
def com_base12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/com_base13")
def com_base13():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータ基礎/com_base13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_base13_Review',methods = ["post"])
def com_base13_Review():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_base13_mihyouka_Review", methods=["POST"])
def com_base13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータ基礎/com_base13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_base13_video',methods =["post"])
def com_base13_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_base13_mihyouka_video',methods =["post"])
def com_base13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/com_base14")
def com_base14():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータ基礎/com_base14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_base14_Review',methods = ["post"])
def com_base14_Review():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_base14_mihyouka_Review", methods=["POST"])
def com_base14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータ基礎/com_base14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_base14_video',methods =["post"])
def com_base14_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_base14_mihyouka_video',methods =["post"])
def com_base14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/com_base15")
def com_base15():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/コンピュータ基礎/com_base15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/com_base15_Review',methods = ["post"])
def com_base15_Review():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/com_base15_mihyouka_Review", methods=["POST"])
def com_base15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/コンピュータ基礎/com_base15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/com_base15_video',methods =["post"])
def com_base15_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/com_base15_mihyouka_video',methods =["post"])
def com_base15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/コンピュータ基礎/コンピュータ基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/コンピュータ基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/コンピュータ基礎/com_base15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################ソフトウェア工学####################################
################################################################################################
@app.route("/soft_engi")
def soft_engi():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/ソフトウェア工学/soft_engi_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/soft_engi1")
def soft_engi1():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ソフトウェア工学/soft_engi1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/soft_engi1_Review',methods = ["post"])
def soft_engi1_Review():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/soft_engi1_mihyouka_Review", methods=["POST"])
def soft_engi1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ソフトウェア工学/soft_engi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/soft_engi1_video',methods =["post"])
def soft_engi1_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/soft_engi1_mihyouka_video',methods =["post"])
def soft_engi1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/soft_engi2")
def soft_engi2():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ソフトウェア工学/soft_engi2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/soft_engi2_Review',methods = ["post"])
def soft_engi2_Review():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/soft_engi2_mihyouka_Review", methods=["POST"])
def soft_engi2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ソフトウェア工学/soft_engi2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/soft_engi2_video',methods =["post"])
def soft_engi2_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/soft_engi2_mihyouka_video',methods =["post"])
def soft_engi2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/soft_engi3")
def soft_engi3():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ソフトウェア工学/soft_engi3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/soft_engi3_Review',methods = ["post"])
def soft_engi3_Review():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/soft_engi3_mihyouka_Review", methods=["POST"])
def soft_engi3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ソフトウェア工学/soft_engi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/soft_engi3_video',methods =["post"])
def soft_engi3_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/soft_engi3_mihyouka_video',methods =["post"])
def soft_engi3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/soft_engi4")
def soft_engi4():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ソフトウェア工学/soft_engi4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/soft_engi4_Review',methods = ["post"])
def soft_engi4_Review():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/soft_engi4_mihyouka_Review", methods=["POST"])
def soft_engi4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ソフトウェア工学/soft_engi4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/soft_engi4_video',methods =["post"])
def soft_engi4_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/soft_engi4_mihyouka_video',methods =["post"])
def soft_engi4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/soft_engi5")
def soft_engi5():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ソフトウェア工学/soft_engi5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/soft_engi5_Review',methods = ["post"])
def soft_engi5_Review():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/soft_engi5_mihyouka_Review", methods=["POST"])
def soft_engi5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ソフトウェア工学/soft_engi5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/soft_engi5_video',methods =["post"])
def soft_engi5_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/soft_engi5_mihyouka_video',methods =["post"])
def soft_engi5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/soft_engi6")
def soft_engi6():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ソフトウェア工学/soft_engi6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/soft_engi6_Review',methods = ["post"])
def soft_engi6_Review():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/soft_engi6_mihyouka_Review", methods=["POST"])
def soft_engi6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ソフトウェア工学/soft_engi6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/soft_engi6_video',methods =["post"])
def soft_engi6_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/soft_engi6_mihyouka_video',methods =["post"])
def soft_engi6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/soft_engi7")
def soft_engi7():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ソフトウェア工学/soft_engi7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/soft_engi7_Review',methods = ["post"])
def soft_engi7_Review():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/soft_engi7_mihyouka_Review", methods=["POST"])
def soft_engi7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ソフトウェア工学/soft_engi7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/soft_engi7_video',methods =["post"])
def soft_engi7_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/soft_engi7_mihyouka_video',methods =["post"])
def soft_engi7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/soft_engi8")
def soft_engi8():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ソフトウェア工学/soft_engi8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/soft_engi8_Review',methods = ["post"])
def soft_engi8_Review():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/soft_engi8_mihyouka_Review", methods=["POST"])
def soft_engi8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ソフトウェア工学/soft_engi8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/soft_engi8_video',methods =["post"])
def soft_engi8_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/soft_engi8_mihyouka_video',methods =["post"])
def soft_engi8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/soft_engi9")
def soft_engi9():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ソフトウェア工学/soft_engi9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/soft_engi9_Review',methods = ["post"])
def soft_engi9_Review():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/soft_engi9_mihyouka_Review", methods=["POST"])
def soft_engi9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ソフトウェア工学/soft_engi9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/soft_engi9_video',methods =["post"])
def soft_engi9_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/soft_engi9_mihyouka_video',methods =["post"])
def soft_engi9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/soft_engi10")
def soft_engi10():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ソフトウェア工学/soft_engi10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/soft_engi10_Review',methods = ["post"])
def soft_engi10_Review():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/soft_engi10_mihyouka_Review", methods=["POST"])
def soft_engi10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ソフトウェア工学/soft_engi10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/soft_engi10_video',methods =["post"])
def soft_engi10_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/soft_engi10_mihyouka_video',methods =["post"])
def soft_engi10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/soft_engi11")
def soft_engi11():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ソフトウェア工学/soft_engi11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/soft_engi11_Review',methods = ["post"])
def soft_engi11_Review():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/soft_engi11_mihyouka_Review", methods=["POST"])
def soft_engi11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ソフトウェア工学/soft_engi11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/soft_engi11_video',methods =["post"])
def soft_engi11_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/soft_engi11_mihyouka_video',methods =["post"])
def soft_engi11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/soft_engi12")
def soft_engi12():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ソフトウェア工学/soft_engi12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/soft_engi12_Review',methods = ["post"])
def soft_engi12_Review():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/soft_engi12_mihyouka_Review", methods=["POST"])
def soft_engi12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ソフトウェア工学/soft_engi12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/soft_engi12_video',methods =["post"])
def soft_engi12_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/soft_engi12_mihyouka_video',methods =["post"])
def soft_engi12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/soft_engi13")
def soft_engi13():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ソフトウェア工学/soft_engi13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/soft_engi13_Review',methods = ["post"])
def soft_engi13_Review():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/soft_engi13_mihyouka_Review", methods=["POST"])
def soft_engi13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ソフトウェア工学/soft_engi13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/soft_engi13_video',methods =["post"])
def soft_engi13_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/soft_engi13_mihyouka_video',methods =["post"])
def soft_engi13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ソフトウェア工学/ソフトウェア工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ソフトウェア工学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ソフトウェア工学/soft_engi13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################ディジタル信号処理（情報システム）####################
################################################################################################
@app.route("/DSP")
def DSP():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/ディジタル信号処理（情報システム）/DSP_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/DSP1")
def DSP1():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ディジタル信号処理（情報システム）/DSP1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DSP1_Review',methods = ["post"])
def DSP1_Review():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DSP1_mihyouka_Review", methods=["POST"])
def DSP1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ディジタル信号処理（情報システム）/DSP1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DSP1_video',methods =["post"])
def DSP1_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DSP1_mihyouka_video',methods =["post"])
def DSP1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/DSP2")
def DSP2():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ディジタル信号処理（情報システム）/DSP2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DSP2_Review',methods = ["post"])
def DSP2_Review():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DSP2_mihyouka_Review", methods=["POST"])
def DSP2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ディジタル信号処理（情報システム）/DSP2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DSP2_video',methods =["post"])
def DSP2_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DSP2_mihyouka_video',methods =["post"])
def DSP2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/DSP3")
def DSP3():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ディジタル信号処理（情報システム）/DSP3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DSP3_Review',methods = ["post"])
def DSP3_Review():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DSP3_mihyouka_Review", methods=["POST"])
def DSP3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ディジタル信号処理（情報システム）/DSP3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DSP3_video',methods =["post"])
def DSP3_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DSP3_mihyouka_video',methods =["post"])
def DSP3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/DSP4")
def DSP4():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ディジタル信号処理（情報システム）/DSP4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DSP4_Review',methods = ["post"])
def DSP4_Review():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DSP4_mihyouka_Review", methods=["POST"])
def DSP4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ディジタル信号処理（情報システム）/DSP4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DSP4_video',methods =["post"])
def DSP4_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DSP4_mihyouka_video',methods =["post"])
def DSP4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/DSP5")
def DSP5():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ディジタル信号処理（情報システム）/DSP5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DSP5_Review',methods = ["post"])
def DSP5_Review():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DSP5_mihyouka_Review", methods=["POST"])
def DSP5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ディジタル信号処理（情報システム）/DSP5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DSP5_video',methods =["post"])
def DSP5_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DSP5_mihyouka_video',methods =["post"])
def DSP5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/DSP6")
def DSP6():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ディジタル信号処理（情報システム）/DSP6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DSP6_Review',methods = ["post"])
def DSP6_Review():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DSP6_mihyouka_Review", methods=["POST"])
def DSP6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ディジタル信号処理（情報システム）/DSP6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DSP6_video',methods =["post"])
def DSP6_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DSP6_mihyouka_video',methods =["post"])
def DSP6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/DSP7")
def DSP7():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ディジタル信号処理（情報システム）/DSP7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DSP7_Review',methods = ["post"])
def DSP7_Review():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DSP7_mihyouka_Review", methods=["POST"])
def DSP7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ディジタル信号処理（情報システム）/DSP7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DSP7_video',methods =["post"])
def DSP7_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DSP7_mihyouka_video',methods =["post"])
def DSP7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/DSP8")
def DSP8():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ディジタル信号処理（情報システム）/DSP8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DSP8_Review',methods = ["post"])
def DSP8_Review():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DSP8_mihyouka_Review", methods=["POST"])
def DSP8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ディジタル信号処理（情報システム）/DSP8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DSP8_video',methods =["post"])
def DSP8_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DSP8_mihyouka_video',methods =["post"])
def DSP8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/DSP9")
def DSP9():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ディジタル信号処理（情報システム）/DSP9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DSP9_Review',methods = ["post"])
def DSP9_Review():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DSP9_mihyouka_Review", methods=["POST"])
def DSP9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ディジタル信号処理（情報システム）/DSP9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DSP9_video',methods =["post"])
def DSP9_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DSP9_mihyouka_video',methods =["post"])
def DSP9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/ディジタル信号処理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ディジタル信号処理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ディジタル信号処理（情報システム）/DSP9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################データベースとデータ処理#############################
################################################################################################
@app.route("/DC_DP")
def DC_DP():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/データベースとデータ処理/DC_DP_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/DC_DP1")
def DC_DP1():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/データベースとデータ処理/DC_DP1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DC_DP1_Review',methods = ["post"])
def DC_DP1_Review():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DC_DP1_mihyouka_Review", methods=["POST"])
def DC_DP1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/データベースとデータ処理/DC_DP1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DC_DP1_video',methods =["post"])
def DC_DP1_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DC_DP1_mihyouka_video',methods =["post"])
def DC_DP1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/DC_DP2")
def DC_DP2():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/データベースとデータ処理/DC_DP2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DC_DP2_Review',methods = ["post"])
def DC_DP2_Review():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DC_DP2_mihyouka_Review", methods=["POST"])
def DC_DP2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/データベースとデータ処理/DC_DP2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DC_DP2_video',methods =["post"])
def DC_DP2_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DC_DP2_mihyouka_video',methods =["post"])
def DC_DP2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/DC_DP3")
def DC_DP3():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/データベースとデータ処理/DC_DP3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DC_DP3_Review',methods = ["post"])
def DC_DP3_Review():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DC_DP3_mihyouka_Review", methods=["POST"])
def DC_DP3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/データベースとデータ処理/DC_DP3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DC_DP3_video',methods =["post"])
def DC_DP3_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DC_DP3_mihyouka_video',methods =["post"])
def DC_DP3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/DC_DP4")
def DC_DP4():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/データベースとデータ処理/DC_DP4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DC_DP4_Review',methods = ["post"])
def DC_DP4_Review():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DC_DP4_mihyouka_Review", methods=["POST"])
def DC_DP4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/データベースとデータ処理/DC_DP4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DC_DP4_video',methods =["post"])
def DC_DP4_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DC_DP4_mihyouka_video',methods =["post"])
def DC_DP4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/DC_DP5")
def DC_DP5():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/データベースとデータ処理/DC_DP5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DC_DP5_Review',methods = ["post"])
def DC_DP5_Review():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DC_DP5_mihyouka_Review", methods=["POST"])
def DC_DP5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/データベースとデータ処理/DC_DP5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DC_DP5_video',methods =["post"])
def DC_DP5_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DC_DP5_mihyouka_video',methods =["post"])
def DC_DP5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/DC_DP6")
def DC_DP6():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/データベースとデータ処理/DC_DP6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DC_DP6_Review',methods = ["post"])
def DC_DP6_Review():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DC_DP6_mihyouka_Review", methods=["POST"])
def DC_DP6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/データベースとデータ処理/DC_DP6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DC_DP6_video',methods =["post"])
def DC_DP6_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DC_DP6_mihyouka_video',methods =["post"])
def DC_DP6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/DC_DP7")
def DC_DP7():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/データベースとデータ処理/DC_DP7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DC_DP7_Review',methods = ["post"])
def DC_DP7_Review():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DC_DP7_mihyouka_Review", methods=["POST"])
def DC_DP7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/データベースとデータ処理/DC_DP7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DC_DP7_video',methods =["post"])
def DC_DP7_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DC_DP7_mihyouka_video',methods =["post"])
def DC_DP7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/DC_DP8")
def DC_DP8():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/データベースとデータ処理/DC_DP8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DC_DP8_Review',methods = ["post"])
def DC_DP8_Review():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DC_DP8_mihyouka_Review", methods=["POST"])
def DC_DP8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/データベースとデータ処理/DC_DP8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DC_DP8_video',methods =["post"])
def DC_DP8_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DC_DP8_mihyouka_video',methods =["post"])
def DC_DP8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/DC_DP9")
def DC_DP9():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/データベースとデータ処理/DC_DP9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DC_DP9_Review',methods = ["post"])
def DC_DP9_Review():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DC_DP9_mihyouka_Review", methods=["POST"])
def DC_DP9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/データベースとデータ処理/DC_DP9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DC_DP9_video',methods =["post"])
def DC_DP9_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DC_DP9_mihyouka_video',methods =["post"])
def DC_DP9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/DC_DP10")
def DC_DP10():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/データベースとデータ処理/DC_DP10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DC_DP10_Review',methods = ["post"])
def DC_DP10_Review():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DC_DP10_mihyouka_Review", methods=["POST"])
def DC_DP10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/データベースとデータ処理/DC_DP10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DC_DP10_video',methods =["post"])
def DC_DP10_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DC_DP10_mihyouka_video',methods =["post"])
def DC_DP10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/DC_DP11")
def DC_DP11():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/データベースとデータ処理/DC_DP11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DC_DP11_Review',methods = ["post"])
def DC_DP11_Review():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DC_DP11_mihyouka_Review", methods=["POST"])
def DC_DP11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/データベースとデータ処理/DC_DP11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DC_DP11_video',methods =["post"])
def DC_DP11_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DC_DP11_mihyouka_video',methods =["post"])
def DC_DP11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/DC_DP12")
def DC_DP12():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/データベースとデータ処理/DC_DP12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DC_DP12_Review',methods = ["post"])
def DC_DP12_Review():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DC_DP12_mihyouka_Review", methods=["POST"])
def DC_DP12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/データベースとデータ処理/DC_DP12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DC_DP12_video',methods =["post"])
def DC_DP12_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DC_DP12_mihyouka_video',methods =["post"])
def DC_DP12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/DC_DP13")
def DC_DP13():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/データベースとデータ処理/DC_DP13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DC_DP13_Review',methods = ["post"])
def DC_DP13_Review():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DC_DP13_mihyouka_Review", methods=["POST"])
def DC_DP13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/データベースとデータ処理/DC_DP13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DC_DP13_video',methods =["post"])
def DC_DP13_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DC_DP13_mihyouka_video',methods =["post"])
def DC_DP13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/DC_DP14")
def DC_DP14():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/データベースとデータ処理/DC_DP14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DC_DP14_Review',methods = ["post"])
def DC_DP14_Review():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DC_DP14_mihyouka_Review", methods=["POST"])
def DC_DP14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/データベースとデータ処理/DC_DP14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DC_DP14_video',methods =["post"])
def DC_DP14_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DC_DP14_mihyouka_video',methods =["post"])
def DC_DP14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/DC_DP15")
def DC_DP15():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/データベースとデータ処理/DC_DP15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/DC_DP15_Review',methods = ["post"])
def DC_DP15_Review():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/DC_DP15_mihyouka_Review", methods=["POST"])
def DC_DP15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/データベースとデータ処理/DC_DP15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/DC_DP15_video',methods =["post"])
def DC_DP15_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/DC_DP15_mihyouka_video',methods =["post"])
def DC_DP15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/データベースとデータ処理/データベースとデータ処理.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/データベースとデータ処理/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/データベースとデータ処理/DC_DP15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


################################################################################################
#############################################ドイツ語１##########################################
################################################################################################
@app.route("/German1_")
def German1_():
    df_key = pd.read_csv("Kamoku/ドイツ語１/ドイツ語１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/ドイツ語１/German1__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/German1_1")
def German1_1():
    df_key = pd.read_csv("Kamoku/ドイツ語１/ドイツ語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ドイツ語１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ドイツ語１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ドイツ語１/German1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/German1_1_Review',methods = ["post"])
def German1_1_Review():
    df_key = pd.read_csv("Kamoku/ドイツ語１/ドイツ語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ドイツ語１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ドイツ語１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ドイツ語１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ドイツ語１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ドイツ語１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ドイツ語１/German1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/German1_1_mihyouka_Review", methods=["POST"])
def German1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ドイツ語１/ドイツ語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ドイツ語１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ドイツ語１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ドイツ語１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ドイツ語１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ドイツ語１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ドイツ語１/German1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/German1_1_video',methods =["post"])
def German1_1_video():
    df_key = pd.read_csv("Kamoku/ドイツ語１/ドイツ語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ドイツ語１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ドイツ語１/German1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/German1_1_mihyouka_video',methods =["post"])
def German1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ドイツ語１/ドイツ語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ドイツ語１/German1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/German1_2")
def German1_2():
    df_key = pd.read_csv("Kamoku/ドイツ語１/ドイツ語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ドイツ語１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ドイツ語１/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ドイツ語１/German1_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/German1_2_Review',methods = ["post"])
def German1_2_Review():
    df_key = pd.read_csv("Kamoku/ドイツ語１/ドイツ語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ドイツ語１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ドイツ語１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ドイツ語１/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ドイツ語１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ドイツ語１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ドイツ語１/German1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/German1_2_mihyouka_Review", methods=["POST"])
def German1_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ドイツ語１/ドイツ語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ドイツ語１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ドイツ語１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ドイツ語１/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ドイツ語１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ドイツ語１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ドイツ語１/German1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/German1_2_video',methods =["post"])
def German1_2_video():
    df_key = pd.read_csv("Kamoku/ドイツ語１/ドイツ語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ドイツ語１/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ドイツ語１/German1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/German1_2_mihyouka_video',methods =["post"])
def German1_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ドイツ語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ドイツ語１/German1_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################ドイツ語２##########################################
################################################################################################
@app.route("/German2_")
def German2_():
    df_key = pd.read_csv("Kamoku/ドイツ語２/ドイツ語２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/ドイツ語２/German2_syr.html', 
                            key_word1 = keyword[0]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/German2_1")
def German21():
    df_key = pd.read_csv("Kamoku/ドイツ語２/ドイツ語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ドイツ語２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ドイツ語２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ドイツ語２/German21.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/German2_1_Review',methods = ["post"])
def German21_Review():
    df_key = pd.read_csv("Kamoku/ドイツ語２/ドイツ語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ドイツ語２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ドイツ語２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ドイツ語２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ドイツ語２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ドイツ語２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ドイツ語２/German21.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/German2_1_mihyouka_Review", methods=["POST"])
def German21_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ドイツ語２/ドイツ語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ドイツ語２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ドイツ語２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ドイツ語２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ドイツ語２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ドイツ語２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ドイツ語２/German21.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/German2_1_video',methods =["post"])
def German21_video():
    df_key = pd.read_csv("Kamoku/ドイツ語２/ドイツ語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ドイツ語２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ドイツ語２/German21.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/German2_1_mihyouka_video',methods =["post"])
def German21_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ドイツ語２/ドイツ語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ドイツ語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ドイツ語２/German21.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################トピックゼミ１######################################
################################################################################################
@app.route("/topic_semi1_")
def topic_semi1_():
    df_key = pd.read_csv("Kamoku/トピックゼミ１/トピックゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/トピックゼミ１/topic_semi1__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/topic_semi1_1")
def topic_semi1_1():
    df_key = pd.read_csv("Kamoku/トピックゼミ１/トピックゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/トピックゼミ１/topic_semi1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/topic_semi1_1_Review',methods = ["post"])
def topic_semi1_1_Review():
    df_key = pd.read_csv("Kamoku/トピックゼミ１/トピックゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/トピックゼミ１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/トピックゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/トピックゼミ１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ１/topic_semi1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/topic_semi1_1_mihyouka_Review", methods=["POST"])
def topic_semi1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/トピックゼミ１/トピックゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/トピックゼミ１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/トピックゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/トピックゼミ１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/トピックゼミ１/topic_semi1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/topic_semi1_1_video',methods =["post"])
def topic_semi1_1_video():
    df_key = pd.read_csv("Kamoku/トピックゼミ１/トピックゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ１/topic_semi1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/topic_semi1_1_mihyouka_video',methods =["post"])
def topic_semi1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/トピックゼミ１/トピックゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ１/topic_semi1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/topic_semi1_2")
def topic_semi1_2():
    df_key = pd.read_csv("Kamoku/トピックゼミ１/トピックゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/トピックゼミ１/topic_semi1_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/topic_semi1_2_Review',methods = ["post"])
def topic_semi1_2_Review():
    df_key = pd.read_csv("Kamoku/トピックゼミ１/トピックゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/トピックゼミ１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/トピックゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/トピックゼミ１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ１/topic_semi1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/topic_semi1_2_mihyouka_Review", methods=["POST"])
def topic_semi1_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/トピックゼミ１/トピックゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/トピックゼミ１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/トピックゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/トピックゼミ１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/トピックゼミ１/topic_semi1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/topic_semi1_2_video',methods =["post"])
def topic_semi1_2_video():
    df_key = pd.read_csv("Kamoku/トピックゼミ１/トピックゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ１/topic_semi1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/topic_semi1_2_mihyouka_video',methods =["post"])
def topic_semi1_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ１/topic_semi1_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/topic_semi1_3")
def topic_semi1_3():
    df_key = pd.read_csv("Kamoku/トピックゼミ１/トピックゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/トピックゼミ１/topic_semi1_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/topic_semi1_3_Review',methods = ["post"])
def topic_semi1_3_Review():
    df_key = pd.read_csv("Kamoku/トピックゼミ１/トピックゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/トピックゼミ１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/トピックゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/トピックゼミ１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ１/topic_semi1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/topic_semi1_3_mihyouka_Review", methods=["POST"])
def topic_semi1_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/トピックゼミ１/トピックゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/トピックゼミ１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/トピックゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/トピックゼミ１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/トピックゼミ１/topic_semi1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/topic_semi1_3_video',methods =["post"])
def topic_semi1_3_video():
    df_key = pd.read_csv("Kamoku/トピックゼミ１/トピックゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ１/topic_semi1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/topic_semi1_3_mihyouka_video',methods =["post"])
def topic_semi1_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/トピックゼミ１/トピックゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ１/topic_semi1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################トピックゼミ２######################################
################################################################################################
@app.route("/topic_semi2_")
def topic_semi2_():
    df_key = pd.read_csv("Kamoku/トピックゼミ２/トピックゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/トピックゼミ２/topic_semi2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/topic_semi2_1")
def topic_semi2_1():
    df_key = pd.read_csv("Kamoku/トピックゼミ２/トピックゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/トピックゼミ２/topic_semi2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/topic_semi2_1_Review',methods = ["post"])
def topic_semi2_1_Review():
    df_key = pd.read_csv("Kamoku/トピックゼミ２/トピックゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/トピックゼミ２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/トピックゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/トピックゼミ２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ２/topic_semi2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/topic_semi2_1_mihyouka_Review", methods=["POST"])
def topic_semi2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/トピックゼミ２/トピックゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/トピックゼミ２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/トピックゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/トピックゼミ２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/トピックゼミ２/topic_semi2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/topic_semi2_1_video',methods =["post"])
def topic_semi2_1_video():
    df_key = pd.read_csv("Kamoku/トピックゼミ２/トピックゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ２/topic_semi2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/topic_semi2_1_mihyouka_video',methods =["post"])
def topic_semi2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/トピックゼミ２/トピックゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ２/topic_semi2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/topic_semi2_2")
def topic_semi2_2():
    df_key = pd.read_csv("Kamoku/トピックゼミ２/トピックゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/トピックゼミ２/topic_semi2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/topic_semi2_2_Review',methods = ["post"])
def topic_semi2_2_Review():
    df_key = pd.read_csv("Kamoku/トピックゼミ２/トピックゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/トピックゼミ２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/トピックゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/トピックゼミ２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ２/topic_semi2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/topic_semi2_2_mihyouka_Review", methods=["POST"])
def topic_semi2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/トピックゼミ２/トピックゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/トピックゼミ２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/トピックゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/トピックゼミ２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/トピックゼミ２/topic_semi2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/topic_semi2_2_video',methods =["post"])
def topic_semi2_2_video():
    df_key = pd.read_csv("Kamoku/トピックゼミ２/トピックゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ２/topic_semi2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/topic_semi2_2_mihyouka_video',methods =["post"])
def topic_semi2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ２/topic_semi2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/topic_semi2_3")
def topic_semi2_3():
    df_key = pd.read_csv("Kamoku/トピックゼミ２/トピックゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/トピックゼミ２/topic_semi2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/topic_semi2_3_Review',methods = ["post"])
def topic_semi2_3_Review():
    df_key = pd.read_csv("Kamoku/トピックゼミ２/トピックゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/トピックゼミ２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/トピックゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/トピックゼミ２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ２/topic_semi2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/topic_semi2_3_mihyouka_Review", methods=["POST"])
def topic_semi2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/トピックゼミ２/トピックゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/トピックゼミ２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/トピックゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/トピックゼミ２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/トピックゼミ２/topic_semi2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/topic_semi2_3_video',methods =["post"])
def topic_semi2_3_video():
    df_key = pd.read_csv("Kamoku/トピックゼミ２/トピックゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ２/topic_semi2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/topic_semi2_3_mihyouka_video',methods =["post"])
def topic_semi2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/トピックゼミ２/トピックゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/トピックゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/トピックゼミ２/topic_semi2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )




####################################################################################################################################################################################################
####################################################################################################################################################################################################
####################################################################################################################################################################################################
####################################################################################################################################################################################################
####################################################################################################################################################################################################
####################################################################################################################################################################################################
####################################################################################################################################################################################################
####################################################################################################################################################################################################
####################################################################################################################################################################################################

################################################################################################
#############################################ヒューマンインタフェース#############################
################################################################################################
@app.route("/hum_inter")
def hum_inter():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/ヒューマンインタフェース/hum_inter_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/hum_inter1")
def hum_inter1():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ヒューマンインタフェース/hum_inter1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/hum_inter1_Review',methods = ["post"])
def hum_inter1_Review():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/hum_inter1_mihyouka_Review", methods=["POST"])
def hum_inter1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ヒューマンインタフェース/hum_inter1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/hum_inter1_video',methods =["post"])
def hum_inter1_video():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/hum_inter1_mihyouka_video',methods =["post"])
def hum_inter1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/hum_inter2")
def hum_inter2():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ヒューマンインタフェース/hum_inter2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/hum_inter2_Review',methods = ["post"])
def hum_inter2_Review():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/hum_inter2_mihyouka_Review", methods=["POST"])
def hum_inter2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ヒューマンインタフェース/hum_inter2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/hum_inter2_video',methods =["post"])
def hum_inter2_video():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/hum_inter2_mihyouka_video',methods =["post"])
def hum_inter2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/hum_inter3")
def hum_inter3():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ヒューマンインタフェース/hum_inter3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/hum_inter3_Review',methods = ["post"])
def hum_inter3_Review():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/hum_inter3_mihyouka_Review", methods=["POST"])
def hum_inter3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ヒューマンインタフェース/hum_inter3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/hum_inter3_video',methods =["post"])
def hum_inter3_video():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/hum_inter3_mihyouka_video',methods =["post"])
def hum_inter3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/hum_inter4")
def hum_inter4():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ヒューマンインタフェース/hum_inter4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/hum_inter4_Review',methods = ["post"])
def hum_inter4_Review():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/hum_inter4_mihyouka_Review", methods=["POST"])
def hum_inter4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ヒューマンインタフェース/hum_inter4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/hum_inter4_video',methods =["post"])
def hum_inter4_video():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/hum_inter4_mihyouka_video',methods =["post"])
def hum_inter4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/hum_inter5")
def hum_inter5():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ヒューマンインタフェース/hum_inter5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/hum_inter5_Review',methods = ["post"])
def hum_inter5_Review():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/hum_inter5_mihyouka_Review", methods=["POST"])
def hum_inter5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ヒューマンインタフェース/hum_inter5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/hum_inter5_video',methods =["post"])
def hum_inter5_video():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/hum_inter5_mihyouka_video',methods =["post"])
def hum_inter5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/hum_inter6")
def hum_inter6():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/ヒューマンインタフェース/hum_inter6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/hum_inter6_Review',methods = ["post"])
def hum_inter6_Review():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/hum_inter6_mihyouka_Review", methods=["POST"])
def hum_inter6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/ヒューマンインタフェース/hum_inter6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/hum_inter6_video',methods =["post"])
def hum_inter6_video():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/hum_inter6_mihyouka_video',methods =["post"])
def hum_inter6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/ヒューマンインタフェース/ヒューマンインタフェース.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/ヒューマンインタフェース/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/ヒューマンインタフェース/hum_inter6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################フーリエ解析工学####################################
################################################################################################
@app.route("/fourier")
def fourier():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/フーリエ解析工学/fourier_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/fourier1")
def fourier1():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/フーリエ解析工学/fourier1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/fourier1_Review',methods = ["post"])
def fourier1_Review():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/フーリエ解析工学/fourier1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/fourier1_mihyouka_Review", methods=["POST"])
def fourier1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/フーリエ解析工学/fourier1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/fourier1_video',methods =["post"])
def fourier1_video():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/フーリエ解析工学/fourier1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/fourier1_mihyouka_video',methods =["post"])
def fourier1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/フーリエ解析工学/fourier1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/fourier2")
def fourier2():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/フーリエ解析工学/fourier2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/fourier2_Review',methods = ["post"])
def fourier2_Review():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/フーリエ解析工学/fourier2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/fourier2_mihyouka_Review", methods=["POST"])
def fourier2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/フーリエ解析工学/fourier2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/fourier2_video',methods =["post"])
def fourier2_video():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/フーリエ解析工学/fourier2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/fourier2_mihyouka_video',methods =["post"])
def fourier2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/フーリエ解析工学/fourier2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/fourier3")
def fourier3():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/フーリエ解析工学/fourier3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/fourier3_Review',methods = ["post"])
def fourier3_Review():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/フーリエ解析工学/fourier3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/fourier3_mihyouka_Review", methods=["POST"])
def fourier3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/フーリエ解析工学/fourier3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/fourier3_video',methods =["post"])
def fourier3_video():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/フーリエ解析工学/fourier3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/fourier3_mihyouka_video',methods =["post"])
def fourier3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/フーリエ解析工学/fourier3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/fourier4")
def fourier4():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/フーリエ解析工学/fourier4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/fourier4_Review',methods = ["post"])
def fourier4_Review():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/フーリエ解析工学/fourier4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/fourier4_mihyouka_Review", methods=["POST"])
def fourier4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/フーリエ解析工学/fourier4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/fourier4_video',methods =["post"])
def fourier4_video():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/フーリエ解析工学/fourier4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/fourier4_mihyouka_video',methods =["post"])
def fourier4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/フーリエ解析工学/fourier4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/fourier5")
def fourier5():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/フーリエ解析工学/fourier5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/fourier5_Review',methods = ["post"])
def fourier5_Review():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/フーリエ解析工学/fourier5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/fourier5_mihyouka_Review", methods=["POST"])
def fourier5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/フーリエ解析工学/fourier5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/fourier5_video',methods =["post"])
def fourier5_video():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/フーリエ解析工学/fourier5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/fourier5_mihyouka_video',methods =["post"])
def fourier5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/フーリエ解析工学/フーリエ解析工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/フーリエ解析工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/フーリエ解析工学/fourier5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################プレゼンテーション演習（情報システム）################
################################################################################################
@app.route("/presen_info")
def presen_info():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/プレゼンテーション演習（情報システム）/presen_info_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/presen_info1")
def presen_info1():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プレゼンテーション演習（情報システム）/presen_info1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/presen_info1_Review',methods = ["post"])
def presen_info1_Review():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プレゼンテーション演習（情報システム）/presen_info1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/presen_info1_mihyouka_Review", methods=["POST"])
def presen_info1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プレゼンテーション演習（情報システム）/presen_info1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/presen_info1_video',methods =["post"])
def presen_info1_video():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プレゼンテーション演習（情報システム）/presen_info1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/presen_info1_mihyouka_video',methods =["post"])
def presen_info1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プレゼンテーション演習（情報システム）/presen_info1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/presen_info2")
def presen_info2():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プレゼンテーション演習（情報システム）/presen_info2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/presen_info2_Review',methods = ["post"])
def presen_info2_Review():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プレゼンテーション演習（情報システム）/presen_info2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/presen_info2_mihyouka_Review", methods=["POST"])
def presen_info2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プレゼンテーション演習（情報システム）/presen_info2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/presen_info2_video',methods =["post"])
def presen_info2_video():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プレゼンテーション演習（情報システム）/presen_info2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/presen_info2_mihyouka_video',methods =["post"])
def presen_info2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プレゼンテーション演習（情報システム）/presen_info2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/presen_info3")
def presen_info3():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プレゼンテーション演習（情報システム）/presen_info3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/presen_info3_Review',methods = ["post"])
def presen_info3_Review():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プレゼンテーション演習（情報システム）/presen_info3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/presen_info3_mihyouka_Review", methods=["POST"])
def presen_info3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プレゼンテーション演習（情報システム）/presen_info3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/presen_info3_video',methods =["post"])
def presen_info3_video():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プレゼンテーション演習（情報システム）/presen_info3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/presen_info3_mihyouka_video',methods =["post"])
def presen_info3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プレゼンテーション演習（情報システム）/presen_info3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/presen_info4")
def presen_info4():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プレゼンテーション演習（情報システム）/presen_info4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/presen_info4_Review',methods = ["post"])
def presen_info4_Review():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プレゼンテーション演習（情報システム）/presen_info4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/presen_info4_mihyouka_Review", methods=["POST"])
def presen_info4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プレゼンテーション演習（情報システム）/presen_info4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/presen_info4_video',methods =["post"])
def presen_info4_video():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プレゼンテーション演習（情報システム）/presen_info4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/presen_info4_mihyouka_video',methods =["post"])
def presen_info4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プレゼンテーション演習（情報システム）/presen_info4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/presen_info5")
def presen_info5():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プレゼンテーション演習（情報システム）/presen_info5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/presen_info5_Review',methods = ["post"])
def presen_info5_Review():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プレゼンテーション演習（情報システム）/presen_info5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/presen_info5_mihyouka_Review", methods=["POST"])
def presen_info5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プレゼンテーション演習（情報システム）/presen_info5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/presen_info5_video',methods =["post"])
def presen_info5_video():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プレゼンテーション演習（情報システム）/presen_info5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/presen_info5_mihyouka_video',methods =["post"])
def presen_info5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/プレゼンテーション演習（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プレゼンテーション演習（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プレゼンテーション演習（情報システム）/presen_info5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )




################################################################################################
#############################################プログラミング１####################################
################################################################################################
@app.route("/programming1_")
def programming1_():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/プログラミング１/programming1__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/programming1_1")
def programming1_1():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング１/programming1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming1_1_Review',methods = ["post"])
def programming1_1_Review():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming1_1_mihyouka_Review", methods=["POST"])
def programming1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング１/programming1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming1_1_video',methods =["post"])
def programming1_1_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming1_1_mihyouka_video',methods =["post"])
def programming1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/programming1_2")
def programming1_2():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング１/programming1_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming1_2_Review',methods = ["post"])
def programming1_2_Review():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming1_2_mihyouka_Review", methods=["POST"])
def programming1_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング１/programming1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming1_2_video',methods =["post"])
def programming1_2_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming1_2_mihyouka_video',methods =["post"])
def programming1_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/programming1_3")
def programming1_3():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング１/programming1_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming1_3_Review',methods = ["post"])
def programming1_3_Review():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming1_3_mihyouka_Review", methods=["POST"])
def programming1_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング１/programming1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming1_3_video',methods =["post"])
def programming1_3_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming1_3_mihyouka_video',methods =["post"])
def programming1_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/programming1_4")
def programming1_4():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング１/programming1_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming1_4_Review',methods = ["post"])
def programming1_4_Review():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming1_4_mihyouka_Review", methods=["POST"])
def programming1_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング１/programming1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming1_4_video',methods =["post"])
def programming1_4_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming1_4_mihyouka_video',methods =["post"])
def programming1_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/programming1_5")
def programming1_5():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング１/programming1_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming1_5_Review',methods = ["post"])
def programming1_5_Review():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming1_5_mihyouka_Review", methods=["POST"])
def programming1_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング１/programming1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming1_5_video',methods =["post"])
def programming1_5_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming1_5_mihyouka_video',methods =["post"])
def programming1_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/programming1_6")
def programming1_6():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング１/programming1_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming1_6_Review',methods = ["post"])
def programming1_6_Review():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming1_6_mihyouka_Review", methods=["POST"])
def programming1_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング１/programming1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming1_6_video',methods =["post"])
def programming1_6_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming1_6_mihyouka_video',methods =["post"])
def programming1_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/programming1_7")
def programming1_7():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング１/programming1_7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming1_7_Review',methods = ["post"])
def programming1_7_Review():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming1_7_mihyouka_Review", methods=["POST"])
def programming1_7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング１/programming1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming1_7_video',methods =["post"])
def programming1_7_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming1_7_mihyouka_video',methods =["post"])
def programming1_7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/programming1_8")
def programming1_8():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング１/programming1_8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming1_8_Review',methods = ["post"])
def programming1_8_Review():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming1_8_mihyouka_Review", methods=["POST"])
def programming1_8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング１/programming1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming1_8_video',methods =["post"])
def programming1_8_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming1_8_mihyouka_video',methods =["post"])
def programming1_8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/programming1_9")
def programming1_9():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング１/programming1_9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming1_9_Review',methods = ["post"])
def programming1_9_Review():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming1_9_mihyouka_Review", methods=["POST"])
def programming1_9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング１/programming1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming1_9_video',methods =["post"])
def programming1_9_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming1_9_mihyouka_video',methods =["post"])
def programming1_9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/programming1_10")
def programming1_10():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング１/programming1_10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming1_10_Review',methods = ["post"])
def programming1_10_Review():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming1_10_mihyouka_Review", methods=["POST"])
def programming1_10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング１/programming1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming1_10_video',methods =["post"])
def programming1_10_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming1_10_mihyouka_video',methods =["post"])
def programming1_10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/programming1_11")
def programming1_11():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング１/programming1_11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming1_11_Review',methods = ["post"])
def programming1_11_Review():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming1_11_mihyouka_Review", methods=["POST"])
def programming1_11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング１/programming1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming1_11_video',methods =["post"])
def programming1_11_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming1_11_mihyouka_video',methods =["post"])
def programming1_11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/programming1_12")
def programming1_12():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング１/programming1_12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming1_12_Review',methods = ["post"])
def programming1_12_Review():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming1_12_mihyouka_Review", methods=["POST"])
def programming1_12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング１/programming1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming1_12_video',methods =["post"])
def programming1_12_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming1_12_mihyouka_video',methods =["post"])
def programming1_12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/programming1_13")
def programming1_13():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング１/programming1_13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming1_13_Review',methods = ["post"])
def programming1_13_Review():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming1_13_mihyouka_Review", methods=["POST"])
def programming1_13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング１/programming1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming1_13_video',methods =["post"])
def programming1_13_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming1_13_mihyouka_video',methods =["post"])
def programming1_13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/programming1_14")
def programming1_14():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング１/programming1_14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming1_14_Review',methods = ["post"])
def programming1_14_Review():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming1_14_mihyouka_Review", methods=["POST"])
def programming1_14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング１/programming1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming1_14_video',methods =["post"])
def programming1_14_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming1_14_mihyouka_video',methods =["post"])
def programming1_14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/programming1_15")
def programming1_15():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング１/programming1_15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming1_15_Review',methods = ["post"])
def programming1_15_Review():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming1_15_mihyouka_Review", methods=["POST"])
def programming1_15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング１/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング１/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング１/programming1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming1_15_video',methods =["post"])
def programming1_15_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming1_15_mihyouka_video',methods =["post"])
def programming1_15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング１/プログラミング１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング１/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング１/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング１/programming1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################プログラミング２####################################
################################################################################################
@app.route("/programming2_")
def programming2_():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/プログラミング２/programming2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/programming2_1")
def programming2_1():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング２/programming2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming2_1_Review',methods = ["post"])
def programming2_1_Review():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming2_1_mihyouka_Review", methods=["POST"])
def programming2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング２/programming2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming2_1_video',methods =["post"])
def programming2_1_video():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming2_1_mihyouka_video',methods =["post"])
def programming2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/programming2_2")
def programming2_2():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング２/programming2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming2_2_Review',methods = ["post"])
def programming2_2_Review():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming2_2_mihyouka_Review", methods=["POST"])
def programming2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング２/programming2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming2_2_video',methods =["post"])
def programming2_2_video():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming2_2_mihyouka_video',methods =["post"])
def programming2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/programming2_3")
def programming2_3():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング２/programming2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming2_3_Review',methods = ["post"])
def programming2_3_Review():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming2_3_mihyouka_Review", methods=["POST"])
def programming2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング２/programming2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming2_3_video',methods =["post"])
def programming2_3_video():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming2_3_mihyouka_video',methods =["post"])
def programming2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/programming2_4")
def programming2_4():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング２/programming2_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming2_4_Review',methods = ["post"])
def programming2_4_Review():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming2_4_mihyouka_Review", methods=["POST"])
def programming2_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング２/programming2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming2_4_video',methods =["post"])
def programming2_4_video():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming2_4_mihyouka_video',methods =["post"])
def programming2_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/programming2_5")
def programming2_5():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング２/programming2_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming2_5_Review',methods = ["post"])
def programming2_5_Review():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング２/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming2_5_mihyouka_Review", methods=["POST"])
def programming2_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング２/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング２/programming2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming2_5_video',methods =["post"])
def programming2_5_video():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング２/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming2_5_mihyouka_video',methods =["post"])
def programming2_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング２/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/programming2_6")
def programming2_6():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング２/programming2_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming2_6_Review',methods = ["post"])
def programming2_6_Review():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング２/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming2_6_mihyouka_Review", methods=["POST"])
def programming2_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング２/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング２/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング２/programming2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming2_6_video',methods =["post"])
def programming2_6_video():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング２/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming2_6_mihyouka_video',methods =["post"])
def programming2_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング２/プログラミング２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング２/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング２/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング２/programming2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


################################################################################################
#############################################プログラミング３####################################
################################################################################################
@app.route("/programming3_")
def programming3_():
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/プログラミング３/programming3__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/programming3_1")
def programming3_1():
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング３/programming3_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming3_1_Review',methods = ["post"])
def programming3_1_Review():
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング３/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング３/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング３/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング３/programming3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming3_1_mihyouka_Review", methods=["POST"])
def programming3_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング３/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング３/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング３/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング３/programming3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming3_1_video',methods =["post"])
def programming3_1_video():
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング３/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング３/programming3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming3_1_mihyouka_video',methods =["post"])
def programming3_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング３/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング３/programming3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/programming3_2")
def programming3_2():
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング３/programming3_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming3_2_Review',methods = ["post"])
def programming3_2_Review():
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング３/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング３/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング３/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング３/programming3_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming3_2_mihyouka_Review", methods=["POST"])
def programming3_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング３/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング３/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング３/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング３/programming3_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming3_2_video',methods =["post"])
def programming3_2_video():
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング３/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング３/programming3_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming3_2_mihyouka_video',methods =["post"])
def programming3_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング３/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング３/programming3_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/programming3_3")
def programming3_3():
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング３/programming3_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming3_3_Review',methods = ["post"])
def programming3_3_Review():
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング３/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング３/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング３/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング３/programming3_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming3_3_mihyouka_Review", methods=["POST"])
def programming3_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング３/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング３/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング３/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング３/programming3_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming3_3_video',methods =["post"])
def programming3_3_video():
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング３/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング３/programming3_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming3_3_mihyouka_video',methods =["post"])
def programming3_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング３/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング３/programming3_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/programming3_4")
def programming3_4():
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング３/programming3_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/programming3_4_Review',methods = ["post"])
def programming3_4_Review():
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング３/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング３/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング３/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング３/programming3_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/programming3_4_mihyouka_Review", methods=["POST"])
def programming3_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング３/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング３/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング３/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング３/programming3_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/programming3_4_video',methods =["post"])
def programming3_4_video():
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング３/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング３/programming3_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/programming3_4_mihyouka_video',methods =["post"])
def programming3_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング３/プログラミング３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング３/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング３/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング３/programming3_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################プログラミング演習１####################################
################################################################################################
@app.route("/prog_exe1_")
def prog_exe1_():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/プログラミング演習１/prog_exe1__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/prog_exe1_1")
def prog_exe1_1():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習１/prog_exe1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe1_1_Review',methods = ["post"])
def prog_exe1_1_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe1_1_mihyouka_Review", methods=["POST"])
def prog_exe1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習１/prog_exe1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe1_1_video',methods =["post"])
def prog_exe1_1_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe1_1_mihyouka_video',methods =["post"])
def prog_exe1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/prog_exe1_2")
def prog_exe1_2():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習１/prog_exe1_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe1_2_Review',methods = ["post"])
def prog_exe1_2_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe1_2_mihyouka_Review", methods=["POST"])
def prog_exe1_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習１/prog_exe1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe1_2_video',methods =["post"])
def prog_exe1_2_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe1_2_mihyouka_video',methods =["post"])
def prog_exe1_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/prog_exe1_3")
def prog_exe1_3():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習１/prog_exe1_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe1_3_Review',methods = ["post"])
def prog_exe1_3_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe1_3_mihyouka_Review", methods=["POST"])
def prog_exe1_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習１/prog_exe1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe1_3_video',methods =["post"])
def prog_exe1_3_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe1_3_mihyouka_video',methods =["post"])
def prog_exe1_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/prog_exe1_4")
def prog_exe1_4():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習１/prog_exe1_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe1_4_Review',methods = ["post"])
def prog_exe1_4_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe1_4_mihyouka_Review", methods=["POST"])
def prog_exe1_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習１/prog_exe1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe1_4_video',methods =["post"])
def prog_exe1_4_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe1_4_mihyouka_video',methods =["post"])
def prog_exe1_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/prog_exe1_5")
def prog_exe1_5():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習１/prog_exe1_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe1_5_Review',methods = ["post"])
def prog_exe1_5_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe1_5_mihyouka_Review", methods=["POST"])
def prog_exe1_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習１/prog_exe1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe1_5_video',methods =["post"])
def prog_exe1_5_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe1_5_mihyouka_video',methods =["post"])
def prog_exe1_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/prog_exe1_6")
def prog_exe1_6():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習１/prog_exe1_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe1_6_Review',methods = ["post"])
def prog_exe1_6_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe1_6_mihyouka_Review", methods=["POST"])
def prog_exe1_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習１/prog_exe1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe1_6_video',methods =["post"])
def prog_exe1_6_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe1_6_mihyouka_video',methods =["post"])
def prog_exe1_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/prog_exe1_7")
def prog_exe1_7():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習１/prog_exe1_7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe1_7_Review',methods = ["post"])
def prog_exe1_7_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe1_7_mihyouka_Review", methods=["POST"])
def prog_exe1_7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習１/prog_exe1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe1_7_video',methods =["post"])
def prog_exe1_7_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe1_7_mihyouka_video',methods =["post"])
def prog_exe1_7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/prog_exe1_8")
def prog_exe1_8():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習１/prog_exe1_8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe1_8_Review',methods = ["post"])
def prog_exe1_8_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe1_8_mihyouka_Review", methods=["POST"])
def prog_exe1_8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習１/prog_exe1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe1_8_video',methods =["post"])
def prog_exe1_8_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe1_8_mihyouka_video',methods =["post"])
def prog_exe1_8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/prog_exe1_9")
def prog_exe1_9():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習１/prog_exe1_9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe1_9_Review',methods = ["post"])
def prog_exe1_9_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe1_9_mihyouka_Review", methods=["POST"])
def prog_exe1_9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習１/prog_exe1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe1_9_video',methods =["post"])
def prog_exe1_9_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe1_9_mihyouka_video',methods =["post"])
def prog_exe1_9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/prog_exe1_10")
def prog_exe1_10():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習１/prog_exe1_10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe1_10_Review',methods = ["post"])
def prog_exe1_10_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe1_10_mihyouka_Review", methods=["POST"])
def prog_exe1_10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習１/prog_exe1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe1_10_video',methods =["post"])
def prog_exe1_10_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe1_10_mihyouka_video',methods =["post"])
def prog_exe1_10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/prog_exe1_11")
def prog_exe1_11():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習１/prog_exe1_11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe1_11_Review',methods = ["post"])
def prog_exe1_11_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe1_11_mihyouka_Review", methods=["POST"])
def prog_exe1_11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習１/prog_exe1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe1_11_video',methods =["post"])
def prog_exe1_11_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe1_11_mihyouka_video',methods =["post"])
def prog_exe1_11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/prog_exe1_12")
def prog_exe1_12():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習１/prog_exe1_12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe1_12_Review',methods = ["post"])
def prog_exe1_12_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe1_12_mihyouka_Review", methods=["POST"])
def prog_exe1_12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習１/prog_exe1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe1_12_video',methods =["post"])
def prog_exe1_12_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe1_12_mihyouka_video',methods =["post"])
def prog_exe1_12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/prog_exe1_13")
def prog_exe1_13():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習１/prog_exe1_13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe1_13_Review',methods = ["post"])
def prog_exe1_13_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe1_13_mihyouka_Review", methods=["POST"])
def prog_exe1_13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習１/prog_exe1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe1_13_video',methods =["post"])
def prog_exe1_13_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe1_13_mihyouka_video',methods =["post"])
def prog_exe1_13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/prog_exe1_14")
def prog_exe1_14():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習１/prog_exe1_14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe1_14_Review',methods = ["post"])
def prog_exe1_14_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe1_14_mihyouka_Review", methods=["POST"])
def prog_exe1_14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習１/prog_exe1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe1_14_video',methods =["post"])
def prog_exe1_14_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe1_14_mihyouka_video',methods =["post"])
def prog_exe1_14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/prog_exe1_15")
def prog_exe1_15():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習１/prog_exe1_15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe1_15_Review',methods = ["post"])
def prog_exe1_15_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe1_15_mihyouka_Review", methods=["POST"])
def prog_exe1_15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習１/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習１/prog_exe1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe1_15_video',methods =["post"])
def prog_exe1_15_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe1_15_mihyouka_video',methods =["post"])
def prog_exe1_15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習１/プログラミング演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習１/prog_exe1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################プログラミング演習２####################################
################################################################################################
@app.route("/prog_exe2_")
def prog_exe2_():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/プログラミング演習２/prog_exe2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/prog_exe2_1")
def prog_exe2_1():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習２/prog_exe2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe2_1_Review',methods = ["post"])
def prog_exe2_1_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe2_1_mihyouka_Review", methods=["POST"])
def prog_exe2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習２/prog_exe2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe2_1_video',methods =["post"])
def prog_exe2_1_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe2_1_mihyouka_video',methods =["post"])
def prog_exe2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/prog_exe2_2")
def prog_exe2_2():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習２/prog_exe2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe2_2_Review',methods = ["post"])
def prog_exe2_2_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe2_2_mihyouka_Review", methods=["POST"])
def prog_exe2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習２/prog_exe2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe2_2_video',methods =["post"])
def prog_exe2_2_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe2_2_mihyouka_video',methods =["post"])
def prog_exe2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/prog_exe2_3")
def prog_exe2_3():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習２/prog_exe2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe2_3_Review',methods = ["post"])
def prog_exe2_3_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe2_3_mihyouka_Review", methods=["POST"])
def prog_exe2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習２/prog_exe2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe2_3_video',methods =["post"])
def prog_exe2_3_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe2_3_mihyouka_video',methods =["post"])
def prog_exe2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/prog_exe2_4")
def prog_exe2_4():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習２/prog_exe2_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe2_4_Review',methods = ["post"])
def prog_exe2_4_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe2_4_mihyouka_Review", methods=["POST"])
def prog_exe2_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習２/prog_exe2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe2_4_video',methods =["post"])
def prog_exe2_4_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe2_4_mihyouka_video',methods =["post"])
def prog_exe2_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/prog_exe2_5")
def prog_exe2_5():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習２/prog_exe2_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe2_5_Review',methods = ["post"])
def prog_exe2_5_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe2_5_mihyouka_Review", methods=["POST"])
def prog_exe2_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習２/prog_exe2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe2_5_video',methods =["post"])
def prog_exe2_5_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe2_5_mihyouka_video',methods =["post"])
def prog_exe2_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/prog_exe2_6")
def prog_exe2_6():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習２/prog_exe2_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe2_6_Review',methods = ["post"])
def prog_exe2_6_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe2_6_mihyouka_Review", methods=["POST"])
def prog_exe2_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習２/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習２/prog_exe2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe2_6_video',methods =["post"])
def prog_exe2_6_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe2_6_mihyouka_video',methods =["post"])
def prog_exe2_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習２/プログラミング演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習２/prog_exe2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################プログラミング演習３###################################
################################################################################################
@app.route("/prog_exe3_")
def prog_exe3_():
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/プログラミング演習３/prog_exe3__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/prog_exe3_1")
def prog_exe3_1():
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習３/prog_exe3_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe3_1_Review',methods = ["post"])
def prog_exe3_1_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習３/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習３/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習３/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習３/prog_exe3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe3_1_mihyouka_Review", methods=["POST"])
def prog_exe3_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習３/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習３/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習３/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習３/prog_exe3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe3_1_video',methods =["post"])
def prog_exe3_1_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習３/prog_exe3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe3_1_mihyouka_video',methods =["post"])
def prog_exe3_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習３/prog_exe3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/prog_exe3_2")
def prog_exe3_2():
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習３/prog_exe3_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe3_2_Review',methods = ["post"])
def prog_exe3_2_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習３/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習３/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習３/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習３/prog_exe3_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe3_2_mihyouka_Review", methods=["POST"])
def prog_exe3_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習３/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習３/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習３/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習３/prog_exe3_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe3_2_video',methods =["post"])
def prog_exe3_2_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習３/prog_exe3_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe3_2_mihyouka_video',methods =["post"])
def prog_exe3_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習３/prog_exe3_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/prog_exe3_3")
def prog_exe3_3():
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習３/prog_exe3_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe3_3_Review',methods = ["post"])
def prog_exe3_3_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習３/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習３/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習３/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習３/prog_exe3_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe3_3_mihyouka_Review", methods=["POST"])
def prog_exe3_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習３/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習３/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習３/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習３/prog_exe3_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe3_3_video',methods =["post"])
def prog_exe3_3_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習３/prog_exe3_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe3_3_mihyouka_video',methods =["post"])
def prog_exe3_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習３/prog_exe3_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/prog_exe3_4")
def prog_exe3_4():
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング演習３/prog_exe3_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_exe3_4_Review',methods = ["post"])
def prog_exe3_4_Review():
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング演習３/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習３/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング演習３/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習３/prog_exe3_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_exe3_4_mihyouka_Review", methods=["POST"])
def prog_exe3_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング演習３/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング演習３/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング演習３/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング演習３/prog_exe3_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_exe3_4_video',methods =["post"])
def prog_exe3_4_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習３/prog_exe3_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_exe3_4_mihyouka_video',methods =["post"])
def prog_exe3_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング演習３/プログラミング演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング演習３/prog_exe3_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################プログラミング言語####################################
################################################################################################
@app.route("/prog_lan")
def prog_lan():
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/プログラミング言語/prog_lan_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/prog_lan1")
def prog_lan1():
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング言語/prog_lan1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_lan1_Review',methods = ["post"])
def prog_lan1_Review():
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング言語/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング言語/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング言語/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング言語/prog_lan1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_lan1_mihyouka_Review", methods=["POST"])
def prog_lan1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング言語/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング言語/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング言語/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング言語/prog_lan1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_lan1_video',methods =["post"])
def prog_lan1_video():
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング言語/prog_lan1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_lan1_mihyouka_video',methods =["post"])
def prog_lan1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング言語/prog_lan1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/prog_lan2")
def prog_lan2():
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング言語/prog_lan2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_lan2_Review',methods = ["post"])
def prog_lan2_Review():
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング言語/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング言語/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング言語/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング言語/prog_lan2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_lan2_mihyouka_Review", methods=["POST"])
def prog_lan2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング言語/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング言語/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング言語/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング言語/prog_lan2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_lan2_video',methods =["post"])
def prog_lan2_video():
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング言語/prog_lan2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_lan2_mihyouka_video',methods =["post"])
def prog_lan2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング言語/prog_lan2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/prog_lan3")
def prog_lan3():
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング言語/prog_lan3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_lan3_Review',methods = ["post"])
def prog_lan3_Review():
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング言語/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング言語/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング言語/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング言語/prog_lan3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_lan3_mihyouka_Review", methods=["POST"])
def prog_lan3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング言語/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング言語/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング言語/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング言語/prog_lan3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_lan3_video',methods =["post"])
def prog_lan3_video():
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング言語/prog_lan3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_lan3_mihyouka_video',methods =["post"])
def prog_lan3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング言語/prog_lan3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/prog_lan4")
def prog_lan4():
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/プログラミング言語/prog_lan4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/prog_lan4_Review',methods = ["post"])
def prog_lan4_Review():
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/プログラミング言語/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング言語/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/プログラミング言語/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング言語/prog_lan4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/prog_lan4_mihyouka_Review", methods=["POST"])
def prog_lan4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/プログラミング言語/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/プログラミング言語/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/プログラミング言語/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/プログラミング言語/prog_lan4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/prog_lan4_video',methods =["post"])
def prog_lan4_video():
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング言語/prog_lan4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/prog_lan4_mihyouka_video',methods =["post"])
def prog_lan4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/プログラミング言語/プログラミング言語.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/プログラミング言語/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/プログラミング言語/prog_lan4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################英語基礎１####################################
################################################################################################
@app.route("/english_base1_")
def english_base1_():
    df_key = pd.read_csv("Kamoku/英語基礎１/英語基礎１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/英語基礎１/english_base1__syr.html', 
                            key_word1 = keyword[0]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/english_base1_1")
def english_base1_1():
    df_key = pd.read_csv("Kamoku/英語基礎１/英語基礎１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語基礎１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語基礎１/english_base1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/english_base1_1_Review',methods = ["post"])
def english_base1_1_Review():
    df_key = pd.read_csv("Kamoku/英語基礎１/英語基礎１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語基礎１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語基礎１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語基礎１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語基礎１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎１/english_base1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/english_base1_1_mihyouka_Review", methods=["POST"])
def english_base1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語基礎１/英語基礎１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語基礎１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語基礎１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語基礎１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語基礎１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語基礎１/english_base1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/english_base1_1_video',methods =["post"])
def english_base1_1_video():
    df_key = pd.read_csv("Kamoku/英語基礎１/英語基礎１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語基礎１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎１/english_base1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/english_base1_1_mihyouka_video',methods =["post"])
def english_base1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語基礎１/英語基礎１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語基礎１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語基礎１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎１/english_base1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################英語基礎２####################################
################################################################################################
@app.route("/english_base2_")
def english_base2_():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/英語基礎２/english_base2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/english_base2_1")
def english_base2_1():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語基礎２/english_base2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/english_base2_1_Review',methods = ["post"])
def english_base2_1_Review():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎２/english_base2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/english_base2_1_mihyouka_Review", methods=["POST"])
def english_base2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語基礎２/english_base2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/english_base2_1_video',methods =["post"])
def english_base2_1_video():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語基礎２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎２/english_base2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/english_base2_1_mihyouka_video',methods =["post"])
def english_base2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語基礎２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎２/english_base2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/english_base2_2")
def english_base2_2():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語基礎２/english_base2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/english_base2_2_Review',methods = ["post"])
def english_base2_2_Review():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎２/english_base2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/english_base2_2_mihyouka_Review", methods=["POST"])
def english_base2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語基礎２/english_base2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/english_base2_2_video',methods =["post"])
def english_base2_2_video():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語基礎２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎２/english_base2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/english_base2_2_mihyouka_video',methods =["post"])
def english_base2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語基礎２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎２/english_base2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/english_base2_3")
def english_base2_3():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語基礎２/english_base2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/english_base2_3_Review',methods = ["post"])
def english_base2_3_Review():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎２/english_base2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/english_base2_3_mihyouka_Review", methods=["POST"])
def english_base2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語基礎２/english_base2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/english_base2_3_video',methods =["post"])
def english_base2_3_video():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語基礎２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎２/english_base2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/english_base2_3_mihyouka_video',methods =["post"])
def english_base2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語基礎２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎２/english_base2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/english_base2_4")
def english_base2_4():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語基礎２/english_base2_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/english_base2_4_Review',methods = ["post"])
def english_base2_4_Review():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎２/english_base2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/english_base2_4_mihyouka_Review", methods=["POST"])
def english_base2_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語基礎２/english_base2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/english_base2_4_video',methods =["post"])
def english_base2_4_video():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語基礎２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎２/english_base2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/english_base2_4_mihyouka_video',methods =["post"])
def english_base2_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語基礎２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎２/english_base2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/english_base2_5")
def english_base2_5():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語基礎２/english_base2_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/english_base2_5_Review',methods = ["post"])
def english_base2_5_Review():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎２/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎２/english_base2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/english_base2_5_mihyouka_Review", methods=["POST"])
def english_base2_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎２/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語基礎２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語基礎２/english_base2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/english_base2_5_video',methods =["post"])
def english_base2_5_video():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語基礎２/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎２/english_base2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/english_base2_5_mihyouka_video',methods =["post"])
def english_base2_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語基礎２/英語基礎２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語基礎２/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語基礎２/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎２/english_base2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################英語基礎３####################################
################################################################################################
@app.route("/english_base3_")
def english_base3_():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/英語基礎４/english_base3__syr.html', 
                            key_word1 = keyword[0]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/english_base3_1")
def english_base3_1():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語基礎４/english_base3_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/english_base3_1_Review',methods = ["post"])
def english_base3_1_Review():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/english_base3_1_mihyouka_Review", methods=["POST"])
def english_base3_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語基礎４/english_base3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/english_base3_1_video',methods =["post"])
def english_base3_1_video():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/english_base3_1_mihyouka_video',methods =["post"])
def english_base3_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################英語基礎４####################################
################################################################################################
@app.route("/english_base4_")
def english_base4_():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/英語基礎４/english_base4__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/english_base4_1")
def english_base4_1():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語基礎４/english_base4_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/english_base4_1_Review',methods = ["post"])
def english_base4_1_Review():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base4_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/english_base4_1_mihyouka_Review", methods=["POST"])
def english_base4_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語基礎４/english_base4_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/english_base4_1_video',methods =["post"])
def english_base4_1_video():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base4_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/english_base4_1_mihyouka_video',methods =["post"])
def english_base4_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base4_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/english_base4_2")
def english_base4_2():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語基礎４/english_base4_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/english_base4_2_Review',methods = ["post"])
def english_base4_2_Review():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎４/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base4_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/english_base4_2_mihyouka_Review", methods=["POST"])
def english_base4_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎４/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語基礎４/english_base4_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/english_base4_2_video',methods =["post"])
def english_base4_2_video():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語基礎４/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base4_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/english_base4_2_mihyouka_video',methods =["post"])
def english_base4_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語基礎４/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base4_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/english_base4_3")
def english_base4_3():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語基礎４/english_base4_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/english_base4_3_Review',methods = ["post"])
def english_base4_3_Review():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎４/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base4_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/english_base4_3_mihyouka_Review", methods=["POST"])
def english_base4_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎４/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語基礎４/english_base4_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/english_base4_3_video',methods =["post"])
def english_base4_3_video():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語基礎４/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base4_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/english_base4_3_mihyouka_video',methods =["post"])
def english_base4_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語基礎４/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base4_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/english_base4_4")
def english_base4_4():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語基礎４/english_base4_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/english_base4_4_Review',methods = ["post"])
def english_base4_4_Review():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎４/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base4_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/english_base4_4_mihyouka_Review", methods=["POST"])
def english_base4_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎４/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語基礎４/english_base4_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/english_base4_4_video',methods =["post"])
def english_base4_4_video():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語基礎４/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base4_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/english_base4_4_mihyouka_video',methods =["post"])
def english_base4_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語基礎４/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base4_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/english_base4_5")
def english_base4_5():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語基礎４/english_base4_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/english_base4_5_Review',methods = ["post"])
def english_base4_5_Review():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎４/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base4_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/english_base4_5_mihyouka_Review", methods=["POST"])
def english_base4_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語基礎４/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語基礎４/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語基礎４/english_base4_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/english_base4_5_video',methods =["post"])
def english_base4_5_video():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語基礎４/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base4_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/english_base4_5_mihyouka_video',methods =["post"])
def english_base4_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語基礎４/英語基礎４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語基礎４/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語基礎４/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語基礎４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語基礎４/english_base4_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################英語特別演習１####################################
################################################################################################
@app.route("/spe_english1_")
def spe_english1_():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/英語特別演習１/spe_english1__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/spe_english1_1")
def spe_english1_1():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習１/spe_english1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english1_1_Review',methods = ["post"])
def spe_english1_1_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習１/spe_english1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english1_1_mihyouka_Review", methods=["POST"])
def spe_english1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習１/spe_english1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english1_1_video',methods =["post"])
def spe_english1_1_video():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習１/spe_english1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english1_1_mihyouka_video',methods =["post"])
def spe_english1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習１/spe_english1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/spe_english1_2")
def spe_english1_2():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習１/spe_english1_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english1_2_Review',methods = ["post"])
def spe_english1_2_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習１/spe_english1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english1_2_mihyouka_Review", methods=["POST"])
def spe_english1_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習１/spe_english1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english1_2_video',methods =["post"])
def spe_english1_2_video():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習１/spe_english1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english1_2_mihyouka_video',methods =["post"])
def spe_english1_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習１/spe_english1_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/spe_english1_3")
def spe_english1_3():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習１/spe_english1_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english1_3_Review',methods = ["post"])
def spe_english1_3_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習１/spe_english1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english1_3_mihyouka_Review", methods=["POST"])
def spe_english1_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習１/spe_english1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english1_3_video',methods =["post"])
def spe_english1_3_video():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習１/spe_english1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english1_3_mihyouka_video',methods =["post"])
def spe_english1_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習１/spe_english1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/spe_english1_4")
def spe_english1_4():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習１/spe_english1_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english1_4_Review',methods = ["post"])
def spe_english1_4_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習１/spe_english1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english1_4_mihyouka_Review", methods=["POST"])
def spe_english1_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習１/spe_english1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english1_4_video',methods =["post"])
def spe_english1_4_video():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習１/spe_english1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english1_4_mihyouka_video',methods =["post"])
def spe_english1_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習１/spe_english1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/spe_english1_5")
def spe_english1_5():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習１/spe_english1_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english1_5_Review',methods = ["post"])
def spe_english1_5_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習１/spe_english1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english1_5_mihyouka_Review", methods=["POST"])
def spe_english1_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習１/spe_english1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english1_5_video',methods =["post"])
def spe_english1_5_video():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習１/spe_english1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english1_5_mihyouka_video',methods =["post"])
def spe_english1_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語特別演習１/英語特別演習１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習１/spe_english1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )




################################################################################################
#############################################英語特別演習２####################################
################################################################################################
@app.route("/spe_english2_")
def spe_english2_():
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/英語特別演習２/spe_english2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/spe_english2_1")
def spe_english2_1():
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習２/spe_english2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english2_1_Review',methods = ["post"])
def spe_english2_1_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習２/spe_english2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english2_1_mihyouka_Review", methods=["POST"])
def spe_english2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習２/spe_english2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english2_1_video',methods =["post"])
def spe_english2_1_video():
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習２/spe_english2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english2_1_mihyouka_video',methods =["post"])
def spe_english2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習２/spe_english2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/spe_english2_2")
def spe_english2_2():
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習２/spe_english2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english2_2_Review',methods = ["post"])
def spe_english2_2_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習２/spe_english2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english2_2_mihyouka_Review", methods=["POST"])
def spe_english2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習２/spe_english2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english2_2_video',methods =["post"])
def spe_english2_2_video():
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習２/spe_english2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english2_2_mihyouka_video',methods =["post"])
def spe_english2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習２/spe_english2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/spe_english2_3")
def spe_english2_3():
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習２/spe_english2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english2_3_Review',methods = ["post"])
def spe_english2_3_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習２/spe_english2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english2_3_mihyouka_Review", methods=["POST"])
def spe_english2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習２/spe_english2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english2_3_video',methods =["post"])
def spe_english2_3_video():
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習２/spe_english2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english2_3_mihyouka_video',methods =["post"])
def spe_english2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習２/spe_english2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/spe_english2_4")
def spe_english2_4():
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習２/spe_english2_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english2_4_Review',methods = ["post"])
def spe_english2_4_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習２/spe_english2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english2_4_mihyouka_Review", methods=["POST"])
def spe_english2_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習２/spe_english2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english2_4_video',methods =["post"])
def spe_english2_4_video():
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習２/spe_english2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english2_4_mihyouka_video',methods =["post"])
def spe_english2_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語特別演習２/英語特別演習２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習２/spe_english2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################英語特別演習３####################################
################################################################################################
@app.route("/spe_english3_")
def spe_english3_():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/英語特別演習３/spe_english3__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/spe_english3_1")
def spe_english3_1():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習３/spe_english3_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english3_1_Review',methods = ["post"])
def spe_english3_1_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習３/spe_english3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english3_1_mihyouka_Review", methods=["POST"])
def spe_english3_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習３/spe_english3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english3_1_video',methods =["post"])
def spe_english3_1_video():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習３/spe_english3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english3_1_mihyouka_video',methods =["post"])
def spe_english3_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習３/spe_english3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/spe_english3_2")
def spe_english3_2():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習３/spe_english3_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english3_2_Review',methods = ["post"])
def spe_english3_2_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習３/spe_english3_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english3_2_mihyouka_Review", methods=["POST"])
def spe_english3_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習３/spe_english3_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english3_2_video',methods =["post"])
def spe_english3_2_video():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習３/spe_english3_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english3_2_mihyouka_video',methods =["post"])
def spe_english3_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習３/spe_english3_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/spe_english3_3")
def spe_english3_3():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習３/spe_english3_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english3_3_Review',methods = ["post"])
def spe_english3_3_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習３/spe_english3_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english3_3_mihyouka_Review", methods=["POST"])
def spe_english3_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習３/spe_english3_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english3_3_video',methods =["post"])
def spe_english3_3_video():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習３/spe_english3_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english3_3_mihyouka_video',methods =["post"])
def spe_english3_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習３/spe_english3_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/spe_english3_4")
def spe_english3_4():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習３/spe_english3_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english3_4_Review',methods = ["post"])
def spe_english3_4_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習３/spe_english3_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english3_4_mihyouka_Review", methods=["POST"])
def spe_english3_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習３/spe_english3_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english3_4_video',methods =["post"])
def spe_english3_4_video():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習３/spe_english3_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english3_4_mihyouka_video',methods =["post"])
def spe_english3_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習３/spe_english3_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/spe_english3_5")
def spe_english3_5():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習３/spe_english3_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english3_5_Review',methods = ["post"])
def spe_english3_5_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習３/spe_english3_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english3_5_mihyouka_Review", methods=["POST"])
def spe_english3_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習３/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習３/spe_english3_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english3_5_video',methods =["post"])
def spe_english3_5_video():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習３/spe_english3_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english3_5_mihyouka_video',methods =["post"])
def spe_english3_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語特別演習３/英語特別演習３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習３/spe_english3_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################英語特別演習４####################################
################################################################################################
@app.route("/spe_english4_")
def spe_english4_():
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/英語特別演習４/spe_english4__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/spe_english4_1")
def spe_english4_1():
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習４/spe_english4_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english4_1_Review',methods = ["post"])
def spe_english4_1_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習４/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習４/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習４/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習４/spe_english4_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english4_1_mihyouka_Review", methods=["POST"])
def spe_english4_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習４/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習４/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習４/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習４/spe_english4_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english4_1_video',methods =["post"])
def spe_english4_1_video():
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習４/spe_english4_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english4_1_mihyouka_video',methods =["post"])
def spe_english4_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習４/spe_english4_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/spe_english4_2")
def spe_english4_2():
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習４/spe_english4_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english4_2_Review',methods = ["post"])
def spe_english4_2_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習４/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習４/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習４/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習４/spe_english4_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english4_2_mihyouka_Review", methods=["POST"])
def spe_english4_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習４/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習４/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習４/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習４/spe_english4_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english4_2_video',methods =["post"])
def spe_english4_2_video():
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習４/spe_english4_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english4_2_mihyouka_video',methods =["post"])
def spe_english4_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習４/spe_english4_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/spe_english4_3")
def spe_english4_3():
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習４/spe_english4_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english4_3_Review',methods = ["post"])
def spe_english4_3_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習４/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習４/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習４/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習４/spe_english4_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english4_3_mihyouka_Review", methods=["POST"])
def spe_english4_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習４/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習４/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習４/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習４/spe_english4_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english4_3_video',methods =["post"])
def spe_english4_3_video():
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習４/spe_english4_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english4_3_mihyouka_video',methods =["post"])
def spe_english4_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習４/spe_english4_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/spe_english4_4")
def spe_english4_4():
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/英語特別演習４/spe_english4_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_english4_4_Review',methods = ["post"])
def spe_english4_4_Review():
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/英語特別演習４/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習４/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/英語特別演習４/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習４/spe_english4_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_english4_4_mihyouka_Review", methods=["POST"])
def spe_english4_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/英語特別演習４/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/英語特別演習４/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/英語特別演習４/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/英語特別演習４/spe_english4_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_english4_4_video',methods =["post"])
def spe_english4_4_video():
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習４/spe_english4_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_english4_4_mihyouka_video',methods =["post"])
def spe_english4_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/英語特別演習４/英語特別演習４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/英語特別演習４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/英語特別演習４/spe_english4_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################化学１####################################
################################################################################################
@app.route("/chemi1_")
def chemi1_():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/化学１/chemi1__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/chemi1_1")
def chemi1_1():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学１/chemi1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi1_1_Review',methods = ["post"])
def chemi1_1_Review():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi1_1_mihyouka_Review", methods=["POST"])
def chemi1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学１/chemi1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi1_1_video',methods =["post"])
def chemi1_1_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi1_1_mihyouka_video',methods =["post"])
def chemi1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/chemi1_2")
def chemi1_2():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学１/chemi1_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi1_2_Review',methods = ["post"])
def chemi1_2_Review():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi1_2_mihyouka_Review", methods=["POST"])
def chemi1_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学１/chemi1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi1_2_video',methods =["post"])
def chemi1_2_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学１/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi1_2_mihyouka_video',methods =["post"])
def chemi1_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学１/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/chemi1_3")
def chemi1_3():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学１/chemi1_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi1_3_Review',methods = ["post"])
def chemi1_3_Review():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi1_3_mihyouka_Review", methods=["POST"])
def chemi1_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学１/chemi1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi1_3_video',methods =["post"])
def chemi1_3_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学１/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi1_3_mihyouka_video',methods =["post"])
def chemi1_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学１/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/chemi1_4")
def chemi1_4():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学１/chemi1_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi1_4_Review',methods = ["post"])
def chemi1_4_Review():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi1_4_mihyouka_Review", methods=["POST"])
def chemi1_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学１/chemi1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi1_4_video',methods =["post"])
def chemi1_4_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学１/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi1_4_mihyouka_video',methods =["post"])
def chemi1_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学１/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/chemi1_5")
def chemi1_5():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学１/chemi1_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi1_5_Review',methods = ["post"])
def chemi1_5_Review():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi1_5_mihyouka_Review", methods=["POST"])
def chemi1_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学１/chemi1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi1_5_video',methods =["post"])
def chemi1_5_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学１/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi1_5_mihyouka_video',methods =["post"])
def chemi1_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学１/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/chemi1_6")
def chemi1_6():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学１/chemi1_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi1_6_Review',methods = ["post"])
def chemi1_6_Review():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学１/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi1_6_mihyouka_Review", methods=["POST"])
def chemi1_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学１/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学１/chemi1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi1_6_video',methods =["post"])
def chemi1_6_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学１/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi1_6_mihyouka_video',methods =["post"])
def chemi1_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学１/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/chemi1_7")
def chemi1_7():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学１/chemi1_7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi1_7_Review',methods = ["post"])
def chemi1_7_Review():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学１/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi1_7_mihyouka_Review", methods=["POST"])
def chemi1_7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学１/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学１/chemi1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi1_7_video',methods =["post"])
def chemi1_7_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学１/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi1_7_mihyouka_video',methods =["post"])
def chemi1_7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学１/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/chemi1_8")
def chemi1_8():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学１/chemi1_8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi1_8_Review',methods = ["post"])
def chemi1_8_Review():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学１/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi1_8_mihyouka_Review", methods=["POST"])
def chemi1_8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学１/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学１/chemi1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi1_8_video',methods =["post"])
def chemi1_8_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学１/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi1_8_mihyouka_video',methods =["post"])
def chemi1_8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学１/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/chemi1_9")
def chemi1_9():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学１/chemi1_9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi1_9_Review',methods = ["post"])
def chemi1_9_Review():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学１/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi1_9_mihyouka_Review", methods=["POST"])
def chemi1_9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学１/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学１/chemi1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi1_9_video',methods =["post"])
def chemi1_9_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学１/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi1_9_mihyouka_video',methods =["post"])
def chemi1_9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学１/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/chemi1_10")
def chemi1_10():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学１/chemi1_10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi1_10_Review',methods = ["post"])
def chemi1_10_Review():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学１/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi1_10_mihyouka_Review", methods=["POST"])
def chemi1_10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学１/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学１/chemi1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi1_10_video',methods =["post"])
def chemi1_10_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学１/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi1_10_mihyouka_video',methods =["post"])
def chemi1_10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学１/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/chemi1_11")
def chemi1_11():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学１/chemi1_11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi1_11_Review',methods = ["post"])
def chemi1_11_Review():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学１/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi1_11_mihyouka_Review", methods=["POST"])
def chemi1_11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学１/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学１/chemi1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi1_11_video',methods =["post"])
def chemi1_11_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学１/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi1_11_mihyouka_video',methods =["post"])
def chemi1_11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学１/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/chemi1_12")
def chemi1_12():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学１/chemi1_12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi1_12_Review',methods = ["post"])
def chemi1_12_Review():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学１/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi1_12_mihyouka_Review", methods=["POST"])
def chemi1_12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学１/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学１/chemi1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi1_12_video',methods =["post"])
def chemi1_12_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学１/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi1_12_mihyouka_video',methods =["post"])
def chemi1_12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学１/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/chemi1_13")
def chemi1_13():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学１/chemi1_13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi1_13_Review',methods = ["post"])
def chemi1_13_Review():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学１/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi1_13_mihyouka_Review", methods=["POST"])
def chemi1_13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学１/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学１/chemi1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi1_13_video',methods =["post"])
def chemi1_13_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学１/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi1_13_mihyouka_video',methods =["post"])
def chemi1_13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学１/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/chemi1_14")
def chemi1_14():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学１/chemi1_14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi1_14_Review',methods = ["post"])
def chemi1_14_Review():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学１/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi1_14_mihyouka_Review", methods=["POST"])
def chemi1_14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学１/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学１/chemi1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi1_14_video',methods =["post"])
def chemi1_14_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学１/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi1_14_mihyouka_video',methods =["post"])
def chemi1_14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学１/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/chemi1_15")
def chemi1_15():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学１/chemi1_15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi1_15_Review',methods = ["post"])
def chemi1_15_Review():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学１/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi1_15_mihyouka_Review", methods=["POST"])
def chemi1_15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学１/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学１/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学１/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学１/chemi1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi1_15_video',methods =["post"])
def chemi1_15_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学１/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi1_15_mihyouka_video',methods =["post"])
def chemi1_15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学１/化学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学１/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学１/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学１/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学１/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学１/chemi1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################化学２###################################
################################################################################################
@app.route("/chemi2_")
def chemi2_():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/化学２/chemi2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/chemi2_1")
def chemi2_1():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学２/chemi2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi2_1_Review',methods = ["post"])
def chemi2_1_Review():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi2_1_mihyouka_Review", methods=["POST"])
def chemi2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学２/chemi2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi2_1_video',methods =["post"])
def chemi2_1_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi2_1_mihyouka_video',methods =["post"])
def chemi2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/chemi2_2")
def chemi2_2():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学２/chemi2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi2_2_Review',methods = ["post"])
def chemi2_2_Review():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi2_2_mihyouka_Review", methods=["POST"])
def chemi2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学２/chemi2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi2_2_video',methods =["post"])
def chemi2_2_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi2_2_mihyouka_video',methods =["post"])
def chemi2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/chemi2_3")
def chemi2_3():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学２/chemi2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi2_3_Review',methods = ["post"])
def chemi2_3_Review():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi2_3_mihyouka_Review", methods=["POST"])
def chemi2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学２/chemi2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi2_3_video',methods =["post"])
def chemi2_3_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi2_3_mihyouka_video',methods =["post"])
def chemi2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/chemi2_4")
def chemi2_4():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学２/chemi2_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi2_4_Review',methods = ["post"])
def chemi2_4_Review():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi2_4_mihyouka_Review", methods=["POST"])
def chemi2_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学２/chemi2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi2_4_video',methods =["post"])
def chemi2_4_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi2_4_mihyouka_video',methods =["post"])
def chemi2_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/chemi2_5")
def chemi2_5():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学２/chemi2_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi2_5_Review',methods = ["post"])
def chemi2_5_Review():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi2_5_mihyouka_Review", methods=["POST"])
def chemi2_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学２/chemi2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi2_5_video',methods =["post"])
def chemi2_5_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学２/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi2_5_mihyouka_video',methods =["post"])
def chemi2_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学２/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/chemi2_6")
def chemi2_6():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学２/chemi2_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi2_6_Review',methods = ["post"])
def chemi2_6_Review():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学２/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi2_6_mihyouka_Review", methods=["POST"])
def chemi2_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学２/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学２/chemi2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi2_6_video',methods =["post"])
def chemi2_6_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学２/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi2_6_mihyouka_video',methods =["post"])
def chemi2_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学２/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/chemi2_7")
def chemi2_7():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学２/chemi2_7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi2_7_Review',methods = ["post"])
def chemi2_7_Review():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学２/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi2_7_mihyouka_Review", methods=["POST"])
def chemi2_7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学２/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学２/chemi2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi2_7_video',methods =["post"])
def chemi2_7_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学２/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi2_7_mihyouka_video',methods =["post"])
def chemi2_7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学２/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/chemi2_8")
def chemi2_8():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学２/chemi2_8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi2_8_Review',methods = ["post"])
def chemi2_8_Review():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学２/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi2_8_mihyouka_Review", methods=["POST"])
def chemi2_8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学２/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学２/chemi2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi2_8_video',methods =["post"])
def chemi2_8_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学２/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi2_8_mihyouka_video',methods =["post"])
def chemi2_8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学２/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/chemi2_9")
def chemi2_9():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学２/chemi2_9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi2_9_Review',methods = ["post"])
def chemi2_9_Review():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学２/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi2_9_mihyouka_Review", methods=["POST"])
def chemi2_9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学２/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学２/chemi2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi2_9_video',methods =["post"])
def chemi2_9_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学２/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi2_9_mihyouka_video',methods =["post"])
def chemi2_9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学２/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/chemi2_10")
def chemi2_10():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学２/chemi2_10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi2_10_Review',methods = ["post"])
def chemi2_10_Review():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学２/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi2_10_mihyouka_Review", methods=["POST"])
def chemi2_10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学２/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学２/chemi2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi2_10_video',methods =["post"])
def chemi2_10_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学２/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi2_10_mihyouka_video',methods =["post"])
def chemi2_10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学２/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/chemi2_11")
def chemi2_11():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学２/chemi2_11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi2_11_Review',methods = ["post"])
def chemi2_11_Review():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学２/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi2_11_mihyouka_Review", methods=["POST"])
def chemi2_11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学２/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学２/chemi2_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi2_11_video',methods =["post"])
def chemi2_11_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学２/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi2_11_mihyouka_video',methods =["post"])
def chemi2_11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学２/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/chemi2_12")
def chemi2_12():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学２/chemi2_12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi2_12_Review',methods = ["post"])
def chemi2_12_Review():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学２/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi2_12_mihyouka_Review", methods=["POST"])
def chemi2_12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学２/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学２/chemi2_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi2_12_video',methods =["post"])
def chemi2_12_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学２/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi2_12_mihyouka_video',methods =["post"])
def chemi2_12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学２/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/chemi2_13")
def chemi2_13():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学２/chemi2_13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi2_13_Review',methods = ["post"])
def chemi2_13_Review():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学２/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi2_13_mihyouka_Review", methods=["POST"])
def chemi2_13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学２/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学２/chemi2_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi2_13_video',methods =["post"])
def chemi2_13_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学２/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi2_13_mihyouka_video',methods =["post"])
def chemi2_13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学２/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/chemi2_14")
def chemi2_14():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学２/chemi2_14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi2_14_Review',methods = ["post"])
def chemi2_14_Review():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学２/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi2_14_mihyouka_Review", methods=["POST"])
def chemi2_14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学２/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学２/chemi2_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi2_14_video',methods =["post"])
def chemi2_14_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学２/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi2_14_mihyouka_video',methods =["post"])
def chemi2_14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学２/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/chemi2_15")
def chemi2_15():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学２/chemi2_15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi2_15_Review',methods = ["post"])
def chemi2_15_Review():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学２/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi2_15_mihyouka_Review", methods=["POST"])
def chemi2_15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学２/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学２/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学２/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学２/chemi2_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi2_15_video',methods =["post"])
def chemi2_15_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学２/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi2_15_mihyouka_video',methods =["post"])
def chemi2_15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学２/化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学２/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学２/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学２/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学２/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学２/chemi2_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################化学実験　後####################################
################################################################################################
@app.route("/chemi_exp")
def chemi_exp():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/化学実験　後/chemi_exp_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/chemi_exp1")
def chemi_exp1():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学実験　後/chemi_exp1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi_exp1_Review',methods = ["post"])
def chemi_exp1_Review():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi_exp1_mihyouka_Review", methods=["POST"])
def chemi_exp1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学実験　後/chemi_exp1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi_exp1_video',methods =["post"])
def chemi_exp1_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi_exp1_mihyouka_video',methods =["post"])
def chemi_exp1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/chemi_exp2")
def chemi_exp2():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学実験　後/chemi_exp2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi_exp2_Review',methods = ["post"])
def chemi_exp2_Review():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi_exp2_mihyouka_Review", methods=["POST"])
def chemi_exp2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学実験　後/chemi_exp2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi_exp2_video',methods =["post"])
def chemi_exp2_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi_exp2_mihyouka_video',methods =["post"])
def chemi_exp2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/chemi_exp3")
def chemi_exp3():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学実験　後/chemi_exp3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi_exp3_Review',methods = ["post"])
def chemi_exp3_Review():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi_exp3_mihyouka_Review", methods=["POST"])
def chemi_exp3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学実験　後/chemi_exp3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi_exp3_video',methods =["post"])
def chemi_exp3_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi_exp3_mihyouka_video',methods =["post"])
def chemi_exp3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/chemi_exp4")
def chemi_exp4():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学実験　後/chemi_exp4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi_exp4_Review',methods = ["post"])
def chemi_exp4_Review():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi_exp4_mihyouka_Review", methods=["POST"])
def chemi_exp4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学実験　後/chemi_exp4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi_exp4_video',methods =["post"])
def chemi_exp4_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi_exp4_mihyouka_video',methods =["post"])
def chemi_exp4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/chemi_exp5")
def chemi_exp5():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学実験　後/chemi_exp5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi_exp5_Review',methods = ["post"])
def chemi_exp5_Review():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi_exp5_mihyouka_Review", methods=["POST"])
def chemi_exp5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学実験　後/chemi_exp5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi_exp5_video',methods =["post"])
def chemi_exp5_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi_exp5_mihyouka_video',methods =["post"])
def chemi_exp5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/chemi_exp6")
def chemi_exp6():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学実験　後/chemi_exp6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi_exp6_Review',methods = ["post"])
def chemi_exp6_Review():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi_exp6_mihyouka_Review", methods=["POST"])
def chemi_exp6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学実験　後/chemi_exp6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi_exp6_video',methods =["post"])
def chemi_exp6_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi_exp6_mihyouka_video',methods =["post"])
def chemi_exp6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/chemi_exp7")
def chemi_exp7():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学実験　後/chemi_exp7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi_exp7_Review',methods = ["post"])
def chemi_exp7_Review():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi_exp7_mihyouka_Review", methods=["POST"])
def chemi_exp7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学実験　後/chemi_exp7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi_exp7_video',methods =["post"])
def chemi_exp7_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi_exp7_mihyouka_video',methods =["post"])
def chemi_exp7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/chemi_exp8")
def chemi_exp8():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学実験　後/chemi_exp8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi_exp8_Review',methods = ["post"])
def chemi_exp8_Review():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi_exp8_mihyouka_Review", methods=["POST"])
def chemi_exp8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学実験　後/chemi_exp8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi_exp8_video',methods =["post"])
def chemi_exp8_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi_exp8_mihyouka_video',methods =["post"])
def chemi_exp8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/chemi_exp9")
def chemi_exp9():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学実験　後/chemi_exp9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi_exp9_Review',methods = ["post"])
def chemi_exp9_Review():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi_exp9_mihyouka_Review", methods=["POST"])
def chemi_exp9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学実験　後/chemi_exp9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi_exp9_video',methods =["post"])
def chemi_exp9_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi_exp9_mihyouka_video',methods =["post"])
def chemi_exp9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/chemi_exp10")
def chemi_exp10():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学実験　後/chemi_exp10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi_exp10_Review',methods = ["post"])
def chemi_exp10_Review():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi_exp10_mihyouka_Review", methods=["POST"])
def chemi_exp10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学実験　後/chemi_exp10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi_exp10_video',methods =["post"])
def chemi_exp10_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi_exp10_mihyouka_video',methods =["post"])
def chemi_exp10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/chemi_exp11")
def chemi_exp11():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学実験　後/chemi_exp11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi_exp11_Review',methods = ["post"])
def chemi_exp11_Review():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi_exp11_mihyouka_Review", methods=["POST"])
def chemi_exp11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学実験　後/chemi_exp11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi_exp11_video',methods =["post"])
def chemi_exp11_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi_exp11_mihyouka_video',methods =["post"])
def chemi_exp11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/chemi_exp12")
def chemi_exp12():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学実験　後/chemi_exp12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi_exp12_Review',methods = ["post"])
def chemi_exp12_Review():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi_exp12_mihyouka_Review", methods=["POST"])
def chemi_exp12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学実験　後/chemi_exp12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi_exp12_video',methods =["post"])
def chemi_exp12_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi_exp12_mihyouka_video',methods =["post"])
def chemi_exp12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/chemi_exp13")
def chemi_exp13():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学実験　後/chemi_exp13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi_exp13_Review',methods = ["post"])
def chemi_exp13_Review():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi_exp13_mihyouka_Review", methods=["POST"])
def chemi_exp13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学実験　後/chemi_exp13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi_exp13_video',methods =["post"])
def chemi_exp13_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi_exp13_mihyouka_video',methods =["post"])
def chemi_exp13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/chemi_exp14")
def chemi_exp14():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学実験　後/chemi_exp14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi_exp14_Review',methods = ["post"])
def chemi_exp14_Review():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi_exp14_mihyouka_Review", methods=["POST"])
def chemi_exp14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学実験　後/chemi_exp14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi_exp14_video',methods =["post"])
def chemi_exp14_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi_exp14_mihyouka_videchemi_expo',methods =["post"])
def chemi_exp14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/chemi_exp15")
def chemi_exp15():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/化学実験　後/chemi_exp15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/chemi_exp15_Review',methods = ["post"])
def chemi_exp15_Review():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/chemi_exp15_mihyouka_Review", methods=["POST"])
def chemi_exp15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/化学実験　後/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/化学実験　後/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/化学実験　後/chemi_exp15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/chemi_exp15_video',methods =["post"])
def chemi_exp15_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/chemi_exp15_mihyouka_video',methods =["post"])
def chemi_exp15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/化学実験　後/化学実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/化学実験　後/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/化学実験　後/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/化学実験　後/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/化学実験　後/chemi_exp15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################科学技術と社会####################################
################################################################################################
@app.route("/tech_soc")
def tech_soc():
    df_key = pd.read_csv("Kamoku/科学技術と社会/科学技術と社会.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/科学技術と社会/tech_soc_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/tech_soc1")
def tech_soc1():
    df_key = pd.read_csv("Kamoku/科学技術と社会/科学技術と社会.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/科学技術と社会/tech_soc1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_soc1_Review',methods = ["post"])
def tech_soc1_Review():
    df_key = pd.read_csv("Kamoku/科学技術と社会/科学技術と社会.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/科学技術と社会/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/科学技術と社会/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/科学技術と社会/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/科学技術と社会/tech_soc1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_soc1_mihyouka_Review", methods=["POST"])
def tech_soc1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/科学技術と社会/科学技術と社会.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/科学技術と社会/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/科学技術と社会/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/科学技術と社会/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/科学技術と社会/tech_soc1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_soc1_video',methods =["post"])
def tech_soc1_video():
    df_key = pd.read_csv("Kamoku/科学技術と社会/科学技術と社会.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/科学技術と社会/tech_soc1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_soc1_mihyouka_video',methods =["post"])
def tech_soc1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/科学技術と社会/科学技術と社会.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/科学技術と社会/tech_soc1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/tech_soc2")
def tech_soc2():
    df_key = pd.read_csv("Kamoku/科学技術と社会/科学技術と社会.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/科学技術と社会/tech_soc2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_soc2_Review',methods = ["post"])
def tech_soc2_Review():
    df_key = pd.read_csv("Kamoku/科学技術と社会/科学技術と社会.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/科学技術と社会/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/科学技術と社会/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/科学技術と社会/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/科学技術と社会/tech_soc2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_soc2_mihyouka_Review", methods=["POST"])
def tech_soc2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/科学技術と社会/科学技術と社会.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/科学技術と社会/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/科学技術と社会/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/科学技術と社会/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/科学技術と社会/tech_soc2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_soc2_video',methods =["post"])
def tech_soc2_video():
    df_key = pd.read_csv("Kamoku/科学技術と社会/科学技術と社会.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/科学技術と社会/tech_soc2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_soc2_mihyouka_video',methods =["post"])
def tech_soc2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/科学技術と社会/tech_soc2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/tech_soc3")
def tech_soc3():
    df_key = pd.read_csv("Kamoku/科学技術と社会/科学技術と社会.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/科学技術と社会/tech_soc3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_soc3_Review',methods = ["post"])
def tech_soc3_Review():
    df_key = pd.read_csv("Kamoku/科学技術と社会/科学技術と社会.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/科学技術と社会/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/科学技術と社会/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/科学技術と社会/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/科学技術と社会/tech_soc3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_soc3_mihyouka_Review", methods=["POST"])
def tech_soc3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/科学技術と社会/科学技術と社会.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/科学技術と社会/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/科学技術と社会/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/科学技術と社会/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/科学技術と社会/tech_soc3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_soc3_video',methods =["post"])
def tech_soc3_video():
    df_key = pd.read_csv("Kamoku/科学技術と社会/科学技術と社会.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/科学技術と社会/tech_soc3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_soc3_mihyouka_video',methods =["post"])
def tech_soc3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/科学技術と社会/科学技術と社会.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/科学技術と社会/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/科学技術と社会/tech_soc3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################科学技術史####################################
################################################################################################
@app.route("/history_sci_tech")
def history_sci_tech():
    df_key = pd.read_csv("Kamoku/科学技術史/科学技術史.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/科学技術史/history_sci_tech_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/history_sci_tech1")
def history_sci_tech1():
    df_key = pd.read_csv("Kamoku/科学技術史/科学技術史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/科学技術史/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/科学技術史/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/科学技術史/history_sci_tech1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/history_sci_tech1_Review',methods = ["post"])
def history_sci_tech1_Review():
    df_key = pd.read_csv("Kamoku/科学技術史/科学技術史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/科学技術史/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/科学技術史/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/科学技術史/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/科学技術史/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/科学技術史/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/科学技術史/history_sci_tech1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/history_sci_tech1_mihyouka_Review", methods=["POST"])
def history_sci_tech1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/科学技術史/科学技術史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/科学技術史/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/科学技術史/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/科学技術史/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/科学技術史/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/科学技術史/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/科学技術史/history_sci_tech1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/history_sci_tech1_video',methods =["post"])
def history_sci_tech1_video():
    df_key = pd.read_csv("Kamoku/科学技術史/科学技術史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/科学技術史/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/科学技術史/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/科学技術史/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/科学技術史/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/科学技術史/history_sci_tech1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/history_sci_tech1_mihyouka_video',methods =["post"])
def history_sci_tech1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/科学技術史/科学技術史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/科学技術史/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/科学技術史/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/科学技術史/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/科学技術史/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/科学技術史/history_sci_tech1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/history_sci_tech2")
def history_sci_tech2():
    df_key = pd.read_csv("Kamoku/科学技術史/科学技術史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/科学技術史/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/科学技術史/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/科学技術史/history_sci_tech2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/history_sci_tech2_Review',methods = ["post"])
def history_sci_tech2_Review():
    df_key = pd.read_csv("Kamoku/科学技術史/科学技術史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/科学技術史/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/科学技術史/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/科学技術史/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/科学技術史/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/科学技術史/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/科学技術史/history_sci_tech2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/history_sci_tech2_mihyouka_Review", methods=["POST"])
def history_sci_tech2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/科学技術史/科学技術史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/科学技術史/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/科学技術史/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/科学技術史/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/科学技術史/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/科学技術史/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/科学技術史/history_sci_tech2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/history_sci_tech2_video',methods =["post"])
def history_sci_tech2_video():
    df_key = pd.read_csv("Kamoku/科学技術史/科学技術史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/科学技術史/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/科学技術史/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/科学技術史/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/科学技術史/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/科学技術史/history_sci_tech2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/history_sci_tech2_mihyouka_video',methods =["post"])
def history_sci_tech2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/科学技術史/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/科学技術史/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/科学技術史/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/科学技術史/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/科学技術史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/科学技術史/history_sci_tech2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
############################################画像処理基礎####################################
################################################################################################
@app.route("/image_process")
def image_process():
    # df_key = pd.read_csv("Kamoku/画像処理基礎/画像処理基礎.csv",encoding="cp932",names= ['key'])
    # keyword = []

    # for i in range(len(df_key)):
        # keyword.append(df_key.loc[i,'key'])

    return render_template('/画像処理基礎/image_process_syr.html')



################################################################################################
############################################確率・統計学####################################
################################################################################################
@app.route("/Pro_Stat")
def Pro_Stat():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/確率・統計学/Pro_Stat_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/Pro_Stat1")
def Pro_Stat1():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/確率・統計学/Pro_Stat1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Pro_Stat1_Review',methods = ["post"])
def Pro_Stat1_Review():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Pro_Stat1_mihyouka_Review", methods=["POST"])
def Pro_Stat1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/確率・統計学/Pro_Stat1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Pro_Stat1_video',methods =["post"])
def Pro_Stat1_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Pro_Stat1_mihyouka_video',methods =["post"])
def Pro_Stat1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/Pro_Stat2")
def Pro_Stat2():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/確率・統計学/Pro_Stat2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Pro_Stat2_Review',methods = ["post"])
def Pro_Stat2_Review():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Pro_Stat2_mihyouka_Review", methods=["POST"])
def Pro_Stat2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/確率・統計学/Pro_Stat2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Pro_Stat2_video',methods =["post"])
def Pro_Stat2_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Pro_Stat2_mihyouka_video',methods =["post"])
def Pro_Stat2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/Pro_Stat3")
def Pro_Stat3():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/確率・統計学/Pro_Stat3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Pro_Stat3_Review',methods = ["post"])
def Pro_Stat3_Review():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Pro_Stat3_mihyouka_Review", methods=["POST"])
def Pro_Stat3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/確率・統計学/Pro_Stat3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Pro_Stat3_video',methods =["post"])
def Pro_Stat3_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Pro_Stat3_mihyouka_video',methods =["post"])
def Pro_Stat3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/Pro_Stat4")
def Pro_Stat4():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/確率・統計学/Pro_Stat4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Pro_Stat4_Review',methods = ["post"])
def Pro_Stat4_Review():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Pro_Stat4_mihyouka_Review", methods=["POST"])
def Pro_Stat4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/確率・統計学/Pro_Stat4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Pro_Stat4_video',methods =["post"])
def Pro_Stat4_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Pro_Stat4_mihyouka_video',methods =["post"])
def Pro_Stat4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/Pro_Stat5")
def Pro_Stat5():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/確率・統計学/Pro_Stat5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Pro_Stat5_Review',methods = ["post"])
def Pro_Stat5_Review():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Pro_Stat5_mihyouka_Review", methods=["POST"])
def Pro_Stat5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/確率・統計学/Pro_Stat5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Pro_Stat5_video',methods =["post"])
def Pro_Stat5_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Pro_Stat5_mihyouka_video',methods =["post"])
def Pro_Stat5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/Pro_Stat6")
def Pro_Stat6():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/確率・統計学/Pro_Stat6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Pro_Stat6_Review',methods = ["post"])
def Pro_Stat6_Review():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Pro_Stat6_mihyouka_Review", methods=["POST"])
def Pro_Stat6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/確率・統計学/Pro_Stat6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Pro_Stat6_video',methods =["post"])
def Pro_Stat6_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Pro_Stat6_mihyouka_video',methods =["post"])
def Pro_Stat6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/Pro_Stat7")
def Pro_Stat7():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/確率・統計学/Pro_Stat7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Pro_Stat7_Review',methods = ["post"])
def Pro_Stat7_Review():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Pro_Stat7_mihyouka_Review", methods=["POST"])
def Pro_Stat7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/確率・統計学/Pro_Stat7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Pro_Stat7_video',methods =["post"])
def Pro_Stat7_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Pro_Stat7_mihyouka_video',methods =["post"])
def Pro_Stat7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/Pro_Stat8")
def Pro_Stat8():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/確率・統計学/Pro_Stat8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Pro_Stat8_Review',methods = ["post"])
def Pro_Stat8_Review():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Pro_Stat8_mihyouka_Review", methods=["POST"])
def Pro_Stat8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/確率・統計学/Pro_Stat8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Pro_Stat8_video',methods =["post"])
def Pro_Stat8_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Pro_Stat8_mihyouka_video',methods =["post"])
def Pro_Stat8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/Pro_Stat9")
def Pro_Stat9():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/確率・統計学/Pro_Stat9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Pro_Stat9_Review',methods = ["post"])
def Pro_Stat9_Review():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Pro_Stat9_mihyouka_Review", methods=["POST"])
def Pro_Stat9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/確率・統計学/Pro_Stat9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Pro_Stat9_video',methods =["post"])
def Pro_Stat9_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Pro_Stat9_mihyouka_video',methods =["post"])
def Pro_Stat9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/Pro_Stat10")
def Pro_Stat10():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/確率・統計学/Pro_Stat10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Pro_Stat10_Review',methods = ["post"])
def Pro_Stat10_Review():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Pro_Stat10_mihyouka_Review", methods=["POST"])
def Pro_Stat10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/確率・統計学/Pro_Stat10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Pro_Stat10_video',methods =["post"])
def Pro_Stat10_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Pro_Stat10_mihyouka_video',methods =["post"])
def Pro_Stat10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/Pro_Stat11")
def Pro_Stat11():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/確率・統計学/Pro_Stat11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Pro_Stat11_Review',methods = ["post"])
def Pro_Stat11_Review():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Pro_Stat11_mihyouka_Review", methods=["POST"])
def Pro_Stat11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/確率・統計学/Pro_Stat11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Pro_Stat11_video',methods =["post"])
def Pro_Stat11_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Pro_Stat11_mihyouka_video',methods =["post"])
def Pro_Stat11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/Pro_Stat12")
def Pro_Stat12():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/確率・統計学/Pro_Stat12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Pro_Stat12_Review',methods = ["post"])
def Pro_Stat12_Review():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Pro_Stat12_mihyouka_Review", methods=["POST"])
def Pro_Stat12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/確率・統計学/Pro_Stat12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Pro_Stat12_video',methods =["post"])
def Pro_Stat12_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Pro_Stat12_mihyouka_video',methods =["post"])
def Pro_Stat12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/Pro_Stat13")
def Pro_Stat13():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/確率・統計学/Pro_Stat13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Pro_Stat13_Review',methods = ["post"])
def Pro_Stat13_Review():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Pro_Stat13_mihyouka_Review", methods=["POST"])
def Pro_Stat13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/確率・統計学/Pro_Stat13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Pro_Stat13_video',methods =["post"])
def Pro_Stat13_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Pro_Stat13_mihyouka_video',methods =["post"])
def Pro_Stat13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/Pro_Stat14")
def Pro_Stat14():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/確率・統計学/Pro_Stat14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Pro_Stat14_Review',methods = ["post"])
def Pro_Stat14_Review():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Pro_Stat14_mihyouka_Review", methods=["POST"])
def Pro_Stat14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/確率・統計学/Pro_Stat14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Pro_Stat14_video',methods =["post"])
def Pro_Stat14_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Pro_Stat14_mihyouka_video',methods =["post"])
def Pro_Stat14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/Pro_Stat15")
def Pro_Stat15():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/確率・統計学/Pro_Stat15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/Pro_Stat15_Review',methods = ["post"])
def Pro_Stat15_Review():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/Pro_Stat15_mihyouka_Review", methods=["POST"])
def Pro_Stat15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/確率・統計学/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/確率・統計学/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/確率・統計学/Pro_Stat15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/Pro_Stat15_video',methods =["post"])
def Pro_Stat15_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/Pro_Stat15_mihyouka_video',methods =["post"])
def Pro_Stat15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/確率・統計学/確率・統計学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/確率・統計学/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/確率・統計学/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/確率・統計学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/確率・統計学/Pro_Stat15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################環境論１####################################
################################################################################################
@app.route("/enviro1_")
def enviro1_():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/環境論１/enviro1__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/enviro1_1")
def enviro1_1():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/環境論１/enviro1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/enviro1_1_Review',methods = ["post"])
def enviro1_1_Review():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/環境論１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/環境論１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論１/enviro1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/enviro1_1_mihyouka_Review", methods=["POST"])
def enviro1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/環境論１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/環境論１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/環境論１/enviro1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/enviro1_1_video',methods =["post"])
def enviro1_1_video():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/環境論１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/環境論１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論１/enviro1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/enviro1_1_mihyouka_video',methods =["post"])
def enviro1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/環境論１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/環境論１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論１/enviro1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/enviro1_2")
def enviro1_2():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/環境論１/enviro1_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/enviro1_2_Review',methods = ["post"])
def enviro1_2_Review():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/環境論１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論１/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/環境論１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論１/enviro1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/enviro1_2_mihyouka_Review", methods=["POST"])
def enviro1_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/環境論１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論１/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/環境論１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/環境論１/enviro1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/enviro1_2_video',methods =["post"])
def enviro1_2_video():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/環境論１/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/環境論１/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論１/enviro1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/enviro1_2_mihyouka_video',methods =["post"])
def enviro1_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/環境論１/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/環境論１/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論１/enviro1_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/enviro1_3")
def enviro1_3():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/環境論１/enviro1_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/enviro1_3_Review',methods = ["post"])
def enviro1_3_Review():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/環境論１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論１/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/環境論１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論１/enviro1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/enviro1_3_mihyouka_Review", methods=["POST"])
def enviro1_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/環境論１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論１/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/環境論１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/環境論１/enviro1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/enviro1_3_video',methods =["post"])
def enviro1_3_video():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/環境論１/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/環境論１/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論１/enviro1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/enviro1_3_mihyouka_video',methods =["post"])
def enviro1_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/環境論１/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/環境論１/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論１/enviro1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/enviro1_4")
def enviro1_4():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/環境論１/enviro1_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/enviro1_4_Review',methods = ["post"])
def enviro1_4_Review():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/環境論１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論１/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/環境論１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論１/enviro1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/enviro1_4_mihyouka_Review", methods=["POST"])
def enviro1_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/環境論１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論１/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/環境論１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/環境論１/enviro1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/enviro1_4_video',methods =["post"])
def enviro1_4_video():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/環境論１/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/環境論１/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論１/enviro1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/enviro1_4_mihyouka_video',methods =["post"])
def enviro1_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/環境論１/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/環境論１/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論１/enviro1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/enviro1_5")
def enviro1_5():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/環境論１/enviro1_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/enviro1_5_Review',methods = ["post"])
def enviro1_5_Review():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/環境論１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論１/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/環境論１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論１/enviro1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/enviro1_5_mihyouka_Review", methods=["POST"])
def enviro1_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/環境論１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論１/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/環境論１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/環境論１/enviro1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/enviro1_5_video',methods =["post"])
def enviro1_5_video():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/環境論１/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/環境論１/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論１/enviro1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/enviro1_5_mihyouka_video',methods =["post"])
def enviro1_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/環境論１/環境論１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/環境論１/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/環境論１/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/環境論１/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論１/enviro1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################環境論２　前期####################################
################################################################################################
@app.route("/enviro2_1st")
def enviro2_1st():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/環境論２　前期/enviro2_1st_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/enviro2_1st1")
def enviro2_1st1():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/環境論２　前期/enviro2_1st1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/enviro2_1st1_Review',methods = ["post"])
def enviro2_1st1_Review():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/enviro2_1st1_mihyouka_Review", methods=["POST"])
def enviro2_1st1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/環境論２　前期/enviro2_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/enviro2_1st1_video',methods =["post"])
def enviro2_1st1_video():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/enviro2_1st1_mihyouka_video',methods =["post"])
def enviro2_1st1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/enviro2_1st2")
def enviro2_1st2():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/環境論２　前期/enviro2_1st2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/enviro2_1st2_Review',methods = ["post"])
def enviro2_1st2_Review():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/enviro2_1st2_mihyouka_Review", methods=["POST"])
def enviro2_1st2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/環境論２　前期/enviro2_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/enviro2_1st2_video',methods =["post"])
def enviro2_1st2_video():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/enviro2_1st2_mihyouka_video',methods =["post"])
def enviro2_1st2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/enviro2_1st3")
def enviro2_1st3():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/環境論２　前期/enviro2_1st3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/enviro2_1st3_Review',methods = ["post"])
def enviro2_1st3_Review():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/enviro2_1st3_mihyouka_Review", methods=["POST"])
def enviro2_1st3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/環境論２　前期/enviro2_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/enviro2_1st3_video',methods =["post"])
def enviro2_1st3_video():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/enviro2_1st3_mihyouka_video',methods =["post"])
def enviro2_1st3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/enviro2_1st4")
def enviro2_1st4():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/環境論２　前期/enviro2_1st4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/enviro2_1st4_Review',methods = ["post"])
def enviro2_1st4_Review():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/enviro2_1st4_mihyouka_Review", methods=["POST"])
def enviro2_1st4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/環境論２　前期/enviro2_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/enviro2_1st4_video',methods =["post"])
def enviro2_1st4_video():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/enviro2_1st4_mihyouka_video',methods =["post"])
def enviro2_1st4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/enviro2_1st5")
def enviro2_1st5():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/環境論２　前期/enviro2_1st5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/enviro2_1st5_Review',methods = ["post"])
def enviro2_1st5_Review():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/enviro2_1st5_mihyouka_Review", methods=["POST"])
def enviro2_1st5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/環境論２　前期/enviro2_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/enviro2_1st5_video',methods =["post"])
def enviro2_1st5_video():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/enviro2_1st5_mihyouka_video',methods =["post"])
def enviro2_1st5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/enviro2_1st6")
def enviro2_1st6():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/環境論２　前期/enviro2_1st6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/enviro2_1st6_Review',methods = ["post"])
def enviro2_1st6_Review():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/enviro2_1st6_mihyouka_Review", methods=["POST"])
def enviro2_1st6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/環境論２　前期/enviro2_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/enviro2_1st6_video',methods =["post"])
def enviro2_1st6_video():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/enviro2_1st6_mihyouka_video',methods =["post"])
def enviro2_1st6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/enviro2_1st7")
def enviro2_1st7():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/環境論２　前期/enviro2_1st7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/enviro2_1st7_Review',methods = ["post"])
def enviro2_1st7_Review():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/enviro2_1st7_mihyouka_Review", methods=["POST"])
def enviro2_1st7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/環境論２　前期/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/環境論２　前期/enviro2_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/enviro2_1st7_video',methods =["post"])
def enviro2_1st7_video():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/enviro2_1st7_mihyouka_video',methods =["post"])
def enviro2_1st7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/環境論２　前期/環境論２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/環境論２　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/環境論２　前期/enviro2_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )




################################################################################################
#############################################企業経営概論（情報システム）#########################
#################################################################################################
@app.route("/business")
def business():
    df_key = pd.read_csv("Kamoku/企業経営概論（情報システム）/企業経営概論（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/企業経営概論（情報システム）/business_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/business1")
def business1():
    df_key = pd.read_csv("Kamoku/企業経営概論（情報システム）/企業経営概論（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/企業経営概論（情報システム）/business1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/business1_Review',methods = ["post"])
def business1_Review():
    df_key = pd.read_csv("Kamoku/企業経営概論（情報システム）/企業経営概論（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/企業経営概論（情報システム）/business1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/business1_mihyouka_Review", methods=["POST"])
def business1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/企業経営概論（情報システム）/企業経営概論（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/企業経営概論（情報システム）/business1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/business1_video',methods =["post"])
def business1_video():
    df_key = pd.read_csv("Kamoku/企業経営概論（情報システム）/企業経営概論（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/企業経営概論（情報システム）/business1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/business1_mihyouka_video',methods =["post"])
def business1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/企業経営概論（情報システム）/企業経営概論（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/企業経営概論（情報システム）/business1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/business2")
def business2():
    df_key = pd.read_csv("Kamoku/企業経営概論（情報システム）/企業経営概論（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/企業経営概論（情報システム）/business2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/business2_Review',methods = ["post"])
def business2_Review():
    df_key = pd.read_csv("Kamoku/企業経営概論（情報システム）/企業経営概論（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/企業経営概論（情報システム）/business2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/business2_mihyouka_Review", methods=["POST"])
def business2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/企業経営概論（情報システム）/企業経営概論（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/企業経営概論（情報システム）/business2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/business2_video',methods =["post"])
def business2_video():
    df_key = pd.read_csv("Kamoku/企業経営概論（情報システム）/企業経営概論（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/企業経営概論（情報システム）/business2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/business2_mihyouka_video',methods =["post"])
def business2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/企業経営概論（情報システム）/business2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/business3")
def business3():
    df_key = pd.read_csv("Kamoku/企業経営概論（情報システム）/企業経営概論（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/企業経営概論（情報システム）/business3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/business3_Review',methods = ["post"])
def business3_Review():
    df_key = pd.read_csv("Kamoku/企業経営概論（情報システム）/企業経営概論（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/企業経営概論（情報システム）/business3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/business3_mihyouka_Review", methods=["POST"])
def business3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/企業経営概論（情報システム）/企業経営概論（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/企業経営概論（情報システム）/business3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/business3_video',methods =["post"])
def business3_video():
    df_key = pd.read_csv("Kamoku/企業経営概論（情報システム）/企業経営概論（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/企業経営概論（情報システム）/business3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/business3_mihyouka_video',methods =["post"])
def business3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/企業経営概論（情報システム）/企業経営概論（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/企業経営概論（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/企業経営概論（情報システム）/business3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################機械学習#############################
################################################################################################
@app.route("/machine_learning")
def machine_learning():
    df_key = pd.read_csv("Kamoku/機械学習/機械学習.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/機械学習/machine_learning_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/machine_learning1")
def machine_learning1():
    df_key = pd.read_csv("Kamoku/機械学習/機械学習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/機械学習/machine_learning1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/machine_learning1_Review',methods = ["post"])
def machine_learning1_Review():
    df_key = pd.read_csv("Kamoku/機械学習/機械学習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/機械学習/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/機械学習/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/機械学習/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/機械学習/machine_learning1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/machine_learning1_mihyouka_Review", methods=["POST"])
def machine_learning1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/機械学習/機械学習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/機械学習/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/機械学習/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/機械学習/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/機械学習/machine_learning1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/machine_learning1_video',methods =["post"])
def machine_learning1_video():
    df_key = pd.read_csv("Kamoku/機械学習/機械学習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/機械学習/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/機械学習/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/機械学習/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/機械学習/machine_learning1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/machine_learning1_mihyouka_video',methods =["post"])
def machine_learning1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/機械学習/機械学習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/機械学習/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/機械学習/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/機械学習/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/機械学習/machine_learning1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/machine_learning2")
def machine_learning2():
    df_key = pd.read_csv("Kamoku/機械学習/機械学習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/機械学習/machine_learning2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/machine_learning2_Review',methods = ["post"])
def machine_learning2_Review():
    df_key = pd.read_csv("Kamoku/機械学習/機械学習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/機械学習/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/機械学習/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/機械学習/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/機械学習/machine_learning2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/machine_learning2_mihyouka_Review", methods=["POST"])
def machine_learning2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/機械学習/機械学習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/機械学習/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/機械学習/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/機械学習/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/機械学習/machine_learning2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/machine_learning2_video',methods =["post"])
def machine_learning2_video():
    df_key = pd.read_csv("Kamoku/機械学習/機械学習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/機械学習/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/機械学習/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/機械学習/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/機械学習/machine_learning2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/machine_learning2_mihyouka_video',methods =["post"])
def machine_learning2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/機械学習/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/機械学習/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/機械学習/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/機械学習/machine_learning2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/machine_learning3")
def machine_learning3():
    df_key = pd.read_csv("Kamoku/機械学習/機械学習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/機械学習/machine_learning3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/machine_learning3_Review',methods = ["post"])
def machine_learning3_Review():
    df_key = pd.read_csv("Kamoku/機械学習/機械学習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/機械学習/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/機械学習/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/機械学習/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/機械学習/machine_learning3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/machine_learning3_mihyouka_Review", methods=["POST"])
def machine_learning3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/機械学習/機械学習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/機械学習/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/機械学習/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/機械学習/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/機械学習/machine_learning3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/machine_learning3_video',methods =["post"])
def machine_learning3_video():
    df_key = pd.read_csv("Kamoku/機械学習/機械学習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/機械学習/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/機械学習/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/機械学習/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/機械学習/machine_learning3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/machine_learning3_mihyouka_video',methods =["post"])
def machine_learning3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/機械学習/機械学習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/機械学習/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/機械学習/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/機械学習/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/機械学習/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/機械学習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/機械学習/machine_learning3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################技術英語（情報システム）#############################
################################################################################################
@app.route("/tech_eng_info")
def tech_eng_info():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/技術英語（情報システム）/tech_eng_info_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/tech_eng_info1")
def tech_eng_info1():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術英語（情報システム）/tech_eng_info1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_eng_info1_Review',methods = ["post"])
def tech_eng_info1_Review():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_eng_info1_mihyouka_Review", methods=["POST"])
def tech_eng_info1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術英語（情報システム）/tech_eng_info1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_eng_info1_video',methods =["post"])
def tech_eng_info1_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_eng_info1_mihyouka_video',methods =["post"])
def tech_eng_info1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/tech_eng_info2")
def tech_eng_info2():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術英語（情報システム）/tech_eng_info2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_eng_info2_Review',methods = ["post"])
def tech_eng_info2_Review():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_eng_info2_mihyouka_Review", methods=["POST"])
def tech_eng_info2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術英語（情報システム）/tech_eng_info2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_eng_info2_video',methods =["post"])
def tech_eng_info2_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_eng_info2_mihyouka_video',methods =["post"])
def tech_eng_info2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/tech_eng_info3")
def tech_eng_info3():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術英語（情報システム）/tech_eng_info3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_eng_info3_Review',methods = ["post"])
def tech_eng_info3_Review():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_eng_info3_mihyouka_Review", methods=["POST"])
def tech_eng_info3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術英語（情報システム）/tech_eng_info3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_eng_info3_video',methods =["post"])
def tech_eng_info3_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_eng_info3_mihyouka_video',methods =["post"])
def tech_eng_info3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/tech_eng_info4")
def tech_eng_info4():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術英語（情報システム）/tech_eng_info4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_eng_info4_Review',methods = ["post"])
def tech_eng_info4_Review():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_eng_info4_mihyouka_Review", methods=["POST"])
def tech_eng_info4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術英語（情報システム）/tech_eng_info4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_eng_info4_video',methods =["post"])
def tech_eng_info4_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_eng_info4_mihyouka_video',methods =["post"])
def tech_eng_info4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/tech_eng_info5")
def tech_eng_info5():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術英語（情報システム）/tech_eng_info5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_eng_info5_Review',methods = ["post"])
def tech_eng_info5_Review():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_eng_info5_mihyouka_Review", methods=["POST"])
def tech_eng_info5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術英語（情報システム）/tech_eng_info5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_eng_info5_video',methods =["post"])
def tech_eng_info5_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_eng_info5_mihyouka_video',methods =["post"])
def tech_eng_info5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/tech_eng_info6")
def tech_eng_info6():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術英語（情報システム）/tech_eng_info6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_eng_info6_Review',methods = ["post"])
def tech_eng_info6_Review():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_eng_info6_mihyouka_Review", methods=["POST"])
def tech_eng_info6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術英語（情報システム）/tech_eng_info6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_eng_info6_video',methods =["post"])
def tech_eng_info6_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_eng_info6_mihyouka_video',methods =["post"])
def tech_eng_info6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/tech_eng_info7")
def tech_eng_info7():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術英語（情報システム）/tech_eng_info7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_eng_info7_Review',methods = ["post"])
def tech_eng_info7_Review():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_eng_info7_mihyouka_Review", methods=["POST"])
def tech_eng_info7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術英語（情報システム）/tech_eng_info7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_eng_info7_video',methods =["post"])
def tech_eng_info7_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_eng_info7_mihyouka_video',methods =["post"])
def tech_eng_info7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/tech_eng_info8")
def tech_eng_info8():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術英語（情報システム）/tech_eng_info8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_eng_info8_Review',methods = ["post"])
def tech_eng_info8_Review():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_eng_info8_mihyouka_Review", methods=["POST"])
def tech_eng_info8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術英語（情報システム）/tech_eng_info8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_eng_info8_video',methods =["post"])
def tech_eng_info8_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_eng_info8_mihyouka_video',methods =["post"])
def tech_eng_info8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/tech_eng_info9")
def tech_eng_info9():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術英語（情報システム）/tech_eng_info9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_eng_info9_Review',methods = ["post"])
def tech_eng_info9_Review():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_eng_info9_mihyouka_Review", methods=["POST"])
def tech_eng_info9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術英語（情報システム）/tech_eng_info9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_eng_info9_video',methods =["post"])
def tech_eng_info9_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_eng_info9_mihyouka_video',methods =["post"])
def tech_eng_info9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/tech_eng_info10")
def tech_eng_info10():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術英語（情報システム）/tech_eng_info10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_eng_info10_Review',methods = ["post"])
def tech_eng_info10_Review():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_eng_info10_mihyouka_Review", methods=["POST"])
def tech_eng_info10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術英語（情報システム）/tech_eng_info10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_eng_info10_video',methods =["post"])
def tech_eng_info10_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_eng_info10_mihyouka_video',methods =["post"])
def tech_eng_info10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/tech_eng_info11")
def tech_eng_info11():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術英語（情報システム）/tech_eng_info11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_eng_info11_Review',methods = ["post"])
def tech_eng_info11_Review():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_eng_info11_mihyouka_Review", methods=["POST"])
def tech_eng_info11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術英語（情報システム）/tech_eng_info11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_eng_info11_video',methods =["post"])
def tech_eng_info11_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_eng_info11_mihyouka_video',methods =["post"])
def tech_eng_info11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/tech_eng_info12")
def tech_eng_info12():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術英語（情報システム）/tech_eng_info12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_eng_info12_Review',methods = ["post"])
def tech_eng_info12_Review():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_eng_info12_mihyouka_Review", methods=["POST"])
def tech_eng_info12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術英語（情報システム）/tech_eng_info12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_eng_info12_video',methods =["post"])
def tech_eng_info12_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_eng_info12_mihyouka_video',methods =["post"])
def tech_eng_info12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/tech_eng_info13")
def tech_eng_info13():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術英語（情報システム）/tech_eng_info13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_eng_info13_Review',methods = ["post"])
def tech_eng_info13_Review():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_eng_info13_mihyouka_Review", methods=["POST"])
def tech_eng_info13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術英語（情報システム）/tech_eng_info13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_eng_info13_video',methods =["post"])
def tech_eng_info13_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_eng_info13_mihyouka_video',methods =["post"])
def tech_eng_info13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/tech_eng_info14")
def tech_eng_info14():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術英語（情報システム）/tech_eng_info14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_eng_info14_Review',methods = ["post"])
def tech_eng_info14_Review():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_eng_info14_mihyouka_Review", methods=["POST"])
def tech_eng_info14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術英語（情報システム）/tech_eng_info14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_eng_info14_video',methods =["post"])
def tech_eng_info14_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_eng_info14_mihyouka_video',methods =["post"])
def tech_eng_info14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/tech_eng_info15")
def tech_eng_info15():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術英語（情報システム）/tech_eng_info15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/tech_eng_info15_Review',methods = ["post"])
def tech_eng_info15_Review():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/tech_eng_info15_mihyouka_Review", methods=["POST"])
def tech_eng_info15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術英語（情報システム）/tech_eng_info15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/tech_eng_info15_video',methods =["post"])
def tech_eng_info15_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/tech_eng_info15_mihyouka_video',methods =["post"])
def tech_eng_info15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術英語（情報システム）/技術英語（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術英語（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術英語（情報システム）/tech_eng_info15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################技術者倫理（情報システム）#############################
################################################################################################
@app.route("/engi_ethic_info")
def engi_ethic_info():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/技術者倫理（情報システム）/engi_ethic_info_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/engi_ethic_info1")
def engi_ethic_info1():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術者倫理（情報システム）/engi_ethic_info1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/engi_ethic_info1_Review',methods = ["post"])
def engi_ethic_info1_Review():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/engi_ethic_info1_mihyouka_Review", methods=["POST"])
def engi_ethic_info1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術者倫理（情報システム）/engi_ethic_info1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/engi_ethic_info1_video',methods =["post"])
def engi_ethic_info1_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/engi_ethic_info1_mihyouka_video',methods =["post"])
def engi_ethic_info1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/engi_ethic_info2")
def engi_ethic_info2():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術者倫理（情報システム）/engi_ethic_info2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/engi_ethic_info2_Review',methods = ["post"])
def engi_ethic_info2_Review():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/engi_ethic_info2_mihyouka_Review", methods=["POST"])
def engi_ethic_info2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術者倫理（情報システム）/engi_ethic_info2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/engi_ethic_info2_video',methods =["post"])
def engi_ethic_info2_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/engi_ethic_info2_mihyouka_video',methods =["post"])
def engi_ethic_info2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/engi_ethic_info3")
def engi_ethic_info3():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術者倫理（情報システム）/engi_ethic_info3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/engi_ethic_info3_Review',methods = ["post"])
def engi_ethic_info3_Review():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/engi_ethic_info3_mihyouka_Review", methods=["POST"])
def engi_ethic_info3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術者倫理（情報システム）/engi_ethic_info3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/engi_ethic_info3_video',methods =["post"])
def engi_ethic_info3_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/engi_ethic_info3_mihyouka_video',methods =["post"])
def engi_ethic_info3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/engi_ethic_info4")
def engi_ethic_info4():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術者倫理（情報システム）/engi_ethic_info4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/engi_ethic_info4_Review',methods = ["post"])
def engi_ethic_info4_Review():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/engi_ethic_info4_mihyouka_Review", methods=["POST"])
def engi_ethic_info4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術者倫理（情報システム）/engi_ethic_info4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/engi_ethic_info4_video',methods =["post"])
def engi_ethic_info4_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/engi_ethic_info4_mihyouka_video',methods =["post"])
def engi_ethic_info4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/engi_ethic_info5")
def engi_ethic_info5():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術者倫理（情報システム）/engi_ethic_info5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/engi_ethic_info5_Review',methods = ["post"])
def engi_ethic_info5_Review():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/engi_ethic_info5_mihyouka_Review", methods=["POST"])
def engi_ethic_info5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術者倫理（情報システム）/engi_ethic_info5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/engi_ethic_info5_video',methods =["post"])
def engi_ethic_info5_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/engi_ethic_info5_mihyouka_video',methods =["post"])
def engi_ethic_info5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/engi_ethic_info6")
def engi_ethic_info6():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術者倫理（情報システム）/engi_ethic_info6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/engi_ethic_info6_Review',methods = ["post"])
def engi_ethic_info6_Review():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/engi_ethic_info6_mihyouka_Review", methods=["POST"])
def engi_ethic_info6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術者倫理（情報システム）/engi_ethic_info6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/engi_ethic_info6_video',methods =["post"])
def engi_ethic_info6_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/engi_ethic_info6_mihyouka_video',methods =["post"])
def engi_ethic_info6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/engi_ethic_info7")
def engi_ethic_info7():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術者倫理（情報システム）/engi_ethic_info7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/engi_ethic_info7_Review',methods = ["post"])
def engi_ethic_info7_Review():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/engi_ethic_info7_mihyouka_Review", methods=["POST"])
def engi_ethic_info7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術者倫理（情報システム）/engi_ethic_info7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/engi_ethic_info7_video',methods =["post"])
def engi_ethic_info7_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/engi_ethic_info7_mihyouka_video',methods =["post"])
def engi_ethic_info7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/engi_ethic_info8")
def engi_ethic_info8():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術者倫理（情報システム）/engi_ethic_info8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/engi_ethic_info8_Review',methods = ["post"])
def engi_ethic_info8_Review():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/engi_ethic_info8_mihyouka_Review", methods=["POST"])
def engi_ethic_info8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術者倫理（情報システム）/engi_ethic_info8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/engi_ethic_info8_video',methods =["post"])
def engi_ethic_info8_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/engi_ethic_info8_mihyouka_video',methods =["post"])
def engi_ethic_info8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/engi_ethic_info9")
def engi_ethic_info9():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術者倫理（情報システム）/engi_ethic_info9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/engi_ethic_info9_Review',methods = ["post"])
def engi_ethic_info9_Review():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/engi_ethic_info9_mihyouka_Review", methods=["POST"])
def engi_ethic_info9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術者倫理（情報システム）/engi_ethic_info9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/engi_ethic_info9_video',methods =["post"])
def engi_ethic_info9_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/engi_ethic_info9_mihyouka_video',methods =["post"])
def engi_ethic_info9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/engi_ethic_info10")
def engi_ethic_info10():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術者倫理（情報システム）/engi_ethic_info10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/engi_ethic_info10_Review',methods = ["post"])
def engi_ethic_info10_Review():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/engi_ethic_info10_mihyouka_Review", methods=["POST"])
def engi_ethic_info10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術者倫理（情報システム）/engi_ethic_info10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/engi_ethic_info10_video',methods =["post"])
def engi_ethic_info10_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/engi_ethic_info10_mihyouka_video',methods =["post"])
def engi_ethic_info10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/engi_ethic_info11")
def engi_ethic_info11():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術者倫理（情報システム）/engi_ethic_info11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/engi_ethic_info11_Review',methods = ["post"])
def engi_ethic_info11_Review():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/engi_ethic_info11_mihyouka_Review", methods=["POST"])
def engi_ethic_info11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術者倫理（情報システム）/engi_ethic_info11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/engi_ethic_info11_video',methods =["post"])
def engi_ethic_info11_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/engi_ethic_info11_mihyouka_video',methods =["post"])
def engi_ethic_info11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/engi_ethic_info12")
def engi_ethic_info12():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術者倫理（情報システム）/engi_ethic_info12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/engi_ethic_info12_Review',methods = ["post"])
def engi_ethic_info12_Review():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/engi_ethic_info12_mihyouka_Review", methods=["POST"])
def engi_ethic_info12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術者倫理（情報システム）/engi_ethic_info12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/engi_ethic_info12_video',methods =["post"])
def engi_ethic_info12_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/engi_ethic_info12_mihyouka_video',methods =["post"])
def engi_ethic_info12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/engi_ethic_info13")
def engi_ethic_info13():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術者倫理（情報システム）/engi_ethic_info13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/engi_ethic_info13_Review',methods = ["post"])
def engi_ethic_info13_Review():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/engi_ethic_info13_mihyouka_Review", methods=["POST"])
def engi_ethic_info13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術者倫理（情報システム）/engi_ethic_info13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/engi_ethic_info13_video',methods =["post"])
def engi_ethic_info13_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/engi_ethic_info13_mihyouka_video',methods =["post"])
def engi_ethic_info13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/engi_ethic_info14")
def engi_ethic_info14():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術者倫理（情報システム）/engi_ethic_info14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/engi_ethic_info14_Review',methods = ["post"])
def engi_ethic_info14_Review():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/engi_ethic_info14_mihyouka_Review", methods=["POST"])
def engi_ethic_info14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術者倫理（情報システム）/engi_ethic_info14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/engi_ethic_info14_video',methods =["post"])
def engi_ethic_info14_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/engi_ethic_info14_mihyouka_video',methods =["post"])
def engi_ethic_info14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/engi_ethic_info15")
def engi_ethic_info15():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/技術者倫理（情報システム）/engi_ethic_info15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/engi_ethic_info15_Review',methods = ["post"])
def engi_ethic_info15_Review():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/engi_ethic_info15_mihyouka_Review", methods=["POST"])
def engi_ethic_info15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/技術者倫理（情報システム）/engi_ethic_info15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/engi_ethic_info15_video',methods =["post"])
def engi_ethic_info15_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/engi_ethic_info15_mihyouka_video',methods =["post"])
def engi_ethic_info15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/技術者倫理（情報システム）/技術者倫理（情報システム）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/技術者倫理（情報システム）/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/技術者倫理（情報システム）/engi_ethic_info15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################教養ゼミ１#############################
################################################################################################
@app.route("/edu_semi1_")
def edu_semi1_():
    df_key = pd.read_csv("Kamoku/教養ゼミ１/教養ゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/教養ゼミ１/edu_semi1__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/edu_semi1_1")
def edu_semi1_1():
    df_key = pd.read_csv("Kamoku/教養ゼミ１/教養ゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/教養ゼミ１/edu_semi1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/edu_semi1_1_Review',methods = ["post"])
def edu_semi1_1_Review():
    df_key = pd.read_csv("Kamoku/教養ゼミ１/教養ゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/教養ゼミ１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/教養ゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/教養ゼミ１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ１/edu_semi1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/edu_semi1_1_mihyouka_Review", methods=["POST"])
def edu_semi1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/教養ゼミ１/教養ゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/教養ゼミ１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/教養ゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/教養ゼミ１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/教養ゼミ１/edu_semi1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/edu_semi1_1_video',methods =["post"])
def edu_semi1_1_video():
    df_key = pd.read_csv("Kamoku/教養ゼミ１/教養ゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ１/edu_semi1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/edu_semi1_1_mihyouka_video',methods =["post"])
def edu_semi1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/教養ゼミ１/教養ゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ１/edu_semi1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/edu_semi1_2")
def edu_semi1_2():
    df_key = pd.read_csv("Kamoku/教養ゼミ１/教養ゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/教養ゼミ１/edu_semi1_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/edu_semi1_2_Review',methods = ["post"])
def edu_semi1_2_Review():
    df_key = pd.read_csv("Kamoku/教養ゼミ１/教養ゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/教養ゼミ１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/教養ゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/教養ゼミ１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ１/edu_semi1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/edu_semi1_2_mihyouka_Review", methods=["POST"])
def edu_semi1_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/教養ゼミ１/教養ゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/教養ゼミ１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/教養ゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/教養ゼミ１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/教養ゼミ１/edu_semi1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/edu_semi1_2_video',methods =["post"])
def edu_semi1_2_video():
    df_key = pd.read_csv("Kamoku/教養ゼミ１/教養ゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ１/edu_semi1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/edu_semi1_2_mihyouka_video',methods =["post"])
def edu_semi1_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ１/edu_semi1_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/edu_semi1_3")
def edu_semi1_3():
    df_key = pd.read_csv("Kamoku/教養ゼミ１/教養ゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/教養ゼミ１/edu_semi1_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/edu_semi1_3_Review',methods = ["post"])
def edu_semi1_3_Review():
    df_key = pd.read_csv("Kamoku/教養ゼミ１/教養ゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/教養ゼミ１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/教養ゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/教養ゼミ１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ１/edu_semi1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/edu_semi1_3_mihyouka_Review", methods=["POST"])
def edu_semi1_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/教養ゼミ１/教養ゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/教養ゼミ１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/教養ゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/教養ゼミ１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/教養ゼミ１/edu_semi1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/edu_semi1_3_video',methods =["post"])
def edu_semi1_3_video():
    df_key = pd.read_csv("Kamoku/教養ゼミ１/教養ゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ１/edu_semi1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/edu_semi1_3_mihyouka_video',methods =["post"])
def edu_semi1_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/教養ゼミ１/教養ゼミ１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ１/edu_semi1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################教養ゼミ２#############################
################################################################################################
@app.route("/edu_semi2_")
def edu_semi2_():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/教養ゼミ２/edu_semi2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/edu_semi2_1")
def edu_semi2_1():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/教養ゼミ２/edu_semi2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/edu_semi2_1_Review',methods = ["post"])
def edu_semi2_1_Review():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ２/edu_semi2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/edu_semi2_1_mihyouka_Review", methods=["POST"])
def edu_semi2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/教養ゼミ２/edu_semi2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/edu_semi2_1_video',methods =["post"])
def edu_semi2_1_video():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ２/edu_semi2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/edu_semi2_1_mihyouka_video',methods =["post"])
def edu_semi2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ２/edu_semi2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/edu_semi2_2")
def edu_semi2_2():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/教養ゼミ２/edu_semi2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/edu_semi2_2_Review',methods = ["post"])
def edu_semi2_2_Review():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ２/edu_semi2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/edu_semi2_2_mihyouka_Review", methods=["POST"])
def edu_semi2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/教養ゼミ２/edu_semi2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/edu_semi2_2_video',methods =["post"])
def edu_semi2_2_video():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ２/edu_semi2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/edu_semi2_2_mihyouka_video',methods =["post"])
def edu_semi2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ２/edu_semi2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/edu_semi2_3")
def edu_semi2_3():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/教養ゼミ２/edu_semi2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/edu_semi2_3_Review',methods = ["post"])
def edu_semi2_3_Review():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ２/edu_semi2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/edu_semi2_3_mihyouka_Review", methods=["POST"])
def edu_semi2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/教養ゼミ２/edu_semi2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/edu_semi2_3_video',methods =["post"])
def edu_semi2_3_video():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ２/edu_semi2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/edu_semi2_3_mihyouka_video',methods =["post"])
def edu_semi2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ２/edu_semi2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/edu_semi2_4")
def edu_semi2_4():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/教養ゼミ２/edu_semi2_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/edu_semi2_4_Review',methods = ["post"])
def edu_semi2_4_Review():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ２/edu_semi2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/edu_semi2_4_mihyouka_Review", methods=["POST"])
def edu_semi2_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/教養ゼミ２/edu_semi2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/edu_semi2_4_video',methods =["post"])
def edu_semi2_4_video():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ２/edu_semi2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/edu_semi2_4_mihyouka_video',methods =["post"])
def edu_semi2_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ２/edu_semi2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/edu_semi2_5")
def edu_semi2_5():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/教養ゼミ２/edu_semi2_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/edu_semi2_5_Review',methods = ["post"])
def edu_semi2_5_Review():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ２/edu_semi2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/edu_semi2_5_mihyouka_Review", methods=["POST"])
def edu_semi2_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/教養ゼミ２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/教養ゼミ２/edu_semi2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/edu_semi2_5_video',methods =["post"])
def edu_semi2_5_video():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ２/edu_semi2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/edu_semi2_5_mihyouka_video',methods =["post"])
def edu_semi2_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/教養ゼミ２/教養ゼミ２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/教養ゼミ２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/教養ゼミ２/edu_semi2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################近現代史#############################
################################################################################################
@app.route("/modern_his")
def modern_his():
    df_key = pd.read_csv("Kamoku/近現代史/近現代史.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/近現代史/modern_his_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/modern_his1")
def modern_his1():
    df_key = pd.read_csv("Kamoku/近現代史/近現代史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/近現代史/modern_his1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/modern_his1_Review',methods = ["post"])
def modern_his1_Review():
    df_key = pd.read_csv("Kamoku/近現代史/近現代史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/近現代史/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/近現代史/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/近現代史/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/近現代史/modern_his1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/modern_his1_mihyouka_Review", methods=["POST"])
def modern_his1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/近現代史/近現代史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/近現代史/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/近現代史/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/近現代史/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/近現代史/modern_his1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/modern_his1_video',methods =["post"])
def modern_his1_video():
    df_key = pd.read_csv("Kamoku/近現代史/近現代史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/近現代史/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/近現代史/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/近現代史/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/近現代史/modern_his1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/modern_his1_mihyouka_video',methods =["post"])
def modern_his1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/近現代史/近現代史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/近現代史/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/近現代史/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/近現代史/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/近現代史/modern_his1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/modern_his2")
def modern_his2():
    df_key = pd.read_csv("Kamoku/近現代史/近現代史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/近現代史/modern_his2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/modern_his2_Review',methods = ["post"])
def modern_his2_Review():
    df_key = pd.read_csv("Kamoku/近現代史/近現代史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/近現代史/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/近現代史/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/近現代史/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/近現代史/modern_his2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/modern_his2_mihyouka_Review", methods=["POST"])
def modern_his2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/近現代史/近現代史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/近現代史/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/近現代史/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/近現代史/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/近現代史/modern_his2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/modern_his2_video',methods =["post"])
def modern_his2_video():
    df_key = pd.read_csv("Kamoku/近現代史/近現代史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/近現代史/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/近現代史/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/近現代史/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/近現代史/modern_his2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/modern_his2_mihyouka_video',methods =["post"])
def modern_his2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/近現代史/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/近現代史/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/近現代史/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/近現代史/modern_his2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/modern_his3")
def modern_his3():
    df_key = pd.read_csv("Kamoku/近現代史/近現代史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/近現代史/modern_his3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/modern_his3_Review',methods = ["post"])
def modern_his3_Review():
    df_key = pd.read_csv("Kamoku/近現代史/近現代史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/近現代史/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/近現代史/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/近現代史/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/近現代史/modern_his3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/modern_his3_mihyouka_Review", methods=["POST"])
def modern_his3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/近現代史/近現代史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/近現代史/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/近現代史/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/近現代史/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/近現代史/modern_his3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/modern_his3_video',methods =["post"])
def modern_his3_video():
    df_key = pd.read_csv("Kamoku/近現代史/近現代史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/近現代史/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/近現代史/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/近現代史/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/近現代史/modern_his3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/modern_his3_mihyouka_video',methods =["post"])
def modern_his3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/近現代史/近現代史.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/近現代史/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/近現代史/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/近現代史/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/近現代史/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/近現代史/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/近現代史/modern_his3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################経済学１　前期#############################
################################################################################################
@app.route("/economics1_1st")
def economics1_1st():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/経済学１　前期/economics1_1st_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/economics1_1st1")
def economics1_1st1():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/経済学１　前期/economics1_1st1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/economics1_1st1_Review',methods = ["post"])
def economics1_1st1_Review():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学１　前期/economics1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/economics1_1st1_mihyouka_Review", methods=["POST"])
def economics1_1st1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/経済学１　前期/economics1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/economics1_1st1_video',methods =["post"])
def economics1_1st1_video():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学１　前期/economics1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/economics1_1st1_mihyouka_video',methods =["post"])
def economics1_1st1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学１　前期/economics1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/economics1_1st2")
def economics1_1st2():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/経済学１　前期/economics1_1st2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/economics1_1st2_Review',methods = ["post"])
def economics1_1st2_Review():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学１　前期/economics1_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/economics1_1st2_mihyouka_Review", methods=["POST"])
def economics1_1st2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/経済学１　前期/economics1_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/economics1_1st2_video',methods =["post"])
def economics1_1st2_video():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学１　前期/economics1_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/economics1_1st2_mihyouka_video',methods =["post"])
def economics1_1st2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学１　前期/economics1_1st2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/economics1_1st3")
def economics1_1st3():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/経済学１　前期/economics1_1st3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/economics1_1st3_Review',methods = ["post"])
def economics1_1st3_Review():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学１　前期/economics1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/economics1_1st3_mihyouka_Review", methods=["POST"])
def economics1_1st3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/経済学１　前期/economics1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/economics1_1st3_video',methods =["post"])
def economics1_1st3_video():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学１　前期/economics1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/economics1_1st3_mihyouka_video',methods =["post"])
def economics1_1st3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学１　前期/economics1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/economics1_1st4")
def economics1_1st4():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/経済学１　前期/economics1_1st4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/economics1_1st4_Review',methods = ["post"])
def economics1_1st4_Review():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学１　前期/economics1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/economics1_1st4_mihyouka_Review", methods=["POST"])
def economics1_1st4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/経済学１　前期/economics1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/economics1_1st4_video',methods =["post"])
def economics1_1st4_video():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学１　前期/economics1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/economics1_1st4_mihyouka_video',methods =["post"])
def economics1_1st4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学１　前期/economics1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/economics1_1st5")
def economics1_1st5():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/経済学１　前期/economics1_1st5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/economics1_1st5_Review',methods = ["post"])
def economics1_1st5_Review():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学１　前期/economics1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/economics1_1st5_mihyouka_Review", methods=["POST"])
def economics1_1st5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/経済学１　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/経済学１　前期/economics1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/economics1_1st5_video',methods =["post"])
def economics1_1st5_video():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学１　前期/economics1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/economics1_1st5_mihyouka_video',methods =["post"])
def economics1_1st5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/経済学１　前期/経済学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/経済学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学１　前期/economics1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################経済学２#############################
################################################################################################
@app.route("/economics2_")
def economics2_():
    df_key = pd.read_csv("Kamoku/経済学２/経済学２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/経済学２/economics2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/economics2_1")
def economics2_1():
    df_key = pd.read_csv("Kamoku/経済学２/経済学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/経済学２/economics2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/economics2_1_Review',methods = ["post"])
def economics2_1_Review():
    df_key = pd.read_csv("Kamoku/経済学２/経済学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/経済学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/経済学２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/経済学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学２/economics2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/economics2_1_mihyouka_Review", methods=["POST"])
def economics2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/経済学２/経済学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/経済学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/経済学２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/経済学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/経済学２/economics2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/economics2_1_video',methods =["post"])
def economics2_1_video():
    df_key = pd.read_csv("Kamoku/経済学２/経済学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/経済学２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/経済学２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/経済学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学２/economics2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/economics2_1_mihyouka_video',methods =["post"])
def economics2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/経済学２/経済学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/経済学２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/経済学２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/経済学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学２/economics2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/economics2_2")
def economics2_2():
    df_key = pd.read_csv("Kamoku/経済学２/経済学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/経済学２/economics2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/economics2_2_Review',methods = ["post"])
def economics2_2_Review():
    df_key = pd.read_csv("Kamoku/経済学２/経済学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/経済学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/経済学２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/経済学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学２/economics2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/economics2_2_mihyouka_Review", methods=["POST"])
def economics2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/経済学２/経済学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/経済学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/経済学２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/経済学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/経済学２/economics2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/economics2_2_video',methods =["post"])
def economics2_2_video():
    df_key = pd.read_csv("Kamoku/経済学２/経済学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/経済学２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/経済学２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/経済学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学２/economics2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/economics2_2_mihyouka_video',methods =["post"])
def economics2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/経済学２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/経済学２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/経済学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学２/economics2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/economics2_3")
def economics2_3():
    df_key = pd.read_csv("Kamoku/経済学２/経済学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/経済学２/economics2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/economics2_3_Review',methods = ["post"])
def economics2_3_Review():
    df_key = pd.read_csv("Kamoku/経済学２/経済学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/経済学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/経済学２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/経済学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学２/economics2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/economics2_3_mihyouka_Review", methods=["POST"])
def economics2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/経済学２/経済学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/経済学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/経済学２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/経済学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/経済学２/economics2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/economics2_3_video',methods =["post"])
def economics2_3_video():
    df_key = pd.read_csv("Kamoku/経済学２/経済学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/経済学２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/経済学２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/経済学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学２/economics2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/economics2_3_mihyouka_video',methods =["post"])
def economics2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/経済学２/経済学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/経済学２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/経済学２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/経済学２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/経済学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/経済学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/経済学２/economics2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################健康科学１ｂ　前期#############################
################################################################################################
@app.route("/health_sci1B")
def health_sci1B():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/健康科学１ｂ　前期/health_sci1B_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/health_sci1B1")
def health_sci1B1():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学１ｂ　前期/health_sci1B1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci1B1_Review',methods = ["post"])
def health_sci1B1_Review():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci1B1_mihyouka_Review", methods=["POST"])
def health_sci1B1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学１ｂ　前期/health_sci1B1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci1B1_video',methods =["post"])
def health_sci1B1_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci1B1_mihyouka_video',methods =["post"])
def health_sci1B1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/health_sci1B2")
def health_sci1B2():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学１ｂ　前期/health_sci1B2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci1B2_Review',methods = ["post"])
def health_sci1B2_Review():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci1B2_mihyouka_Review", methods=["POST"])
def health_sci1B2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学１ｂ　前期/health_sci1B2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci1B2_video',methods =["post"])
def health_sci1B2_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci1B2_mihyouka_video',methods =["post"])
def health_sci1B2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/health_sci1B3")
def health_sci1B3():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学１ｂ　前期/health_sci1B3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci1B3_Review',methods = ["post"])
def health_sci1B3_Review():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci1B3_mihyouka_Review", methods=["POST"])
def health_sci1B3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学１ｂ　前期/health_sci1B3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci1B3_video',methods =["post"])
def health_sci1B3_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci1B3_mihyouka_video',methods =["post"])
def health_sci1B3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/health_sci1B4")
def health_sci1B4():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学１ｂ　前期/health_sci1B4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci1B4_Review',methods = ["post"])
def health_sci1B4_Review():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci1B4_mihyouka_Review", methods=["POST"])
def health_sci1B4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学１ｂ　前期/health_sci1B4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci1B4_video',methods =["post"])
def health_sci1B4_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci1B4_mihyouka_video',methods =["post"])
def health_sci1B4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/health_sci1B5")
def health_sci1B5():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学１ｂ　前期/health_sci1B5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci1B5_Review',methods = ["post"])
def health_sci1B5_Review():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci1B5_mihyouka_Review", methods=["POST"])
def health_sci1B5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学１ｂ　前期/health_sci1B5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci1B5_video',methods =["post"])
def health_sci1B5_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci1B5_mihyouka_video',methods =["post"])
def health_sci1B5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/health_sci1B6")
def health_sci1B6():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学１ｂ　前期/health_sci1B6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci1B6_Review',methods = ["post"])
def health_sci1B6_Review():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci1B6_mihyouka_Review", methods=["POST"])
def health_sci1B6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学１ｂ　前期/health_sci1B6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci1B6_video',methods =["post"])
def health_sci1B6_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci1B6_mihyouka_video',methods =["post"])
def health_sci1B6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/health_sci1B7")
def health_sci1B7():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学１ｂ　前期/health_sci1B7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci1B7_Review',methods = ["post"])
def health_sci1B7_Review():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci1B7_mihyouka_Review", methods=["POST"])
def health_sci1B7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学１ｂ　前期/health_sci1B7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci1B7_video',methods =["post"])
def health_sci1B7_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci1B7_mihyouka_video',methods =["post"])
def health_sci1B7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/health_sci1B8")
def health_sci1B8():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学１ｂ　前期/health_sci1B8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci1B8_Review',methods = ["post"])
def health_sci1B8_Review():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci1B8_mihyouka_Review", methods=["POST"])
def health_sci1B8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学１ｂ　前期/health_sci1B8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci1B8_video',methods =["post"])
def health_sci1B8_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci1B8_mihyouka_video',methods =["post"])
def health_sci1B8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/health_sci1B9")
def health_sci1B9():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学１ｂ　前期/health_sci1B9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci1B9_Review',methods = ["post"])
def health_sci1B9_Review():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci1B9_mihyouka_Review", methods=["POST"])
def health_sci1B9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学１ｂ　前期/health_sci1B9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci1B9_video',methods =["post"])
def health_sci1B9_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci1B9_mihyouka_video',methods =["post"])
def health_sci1B9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/health_sci1B10")
def health_sci1B10():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学１ｂ　前期/health_sci1B10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci1B10_Review',methods = ["post"])
def health_sci1B10_Review():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci1B10_mihyouka_Review", methods=["POST"])
def health_sci1B10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学１ｂ　前期/health_sci1B10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci1B10_video',methods =["post"])
def health_sci1B10_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci1B10_mihyouka_video',methods =["post"])
def health_sci1B10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/health_sci1B11")
def health_sci1B11():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学１ｂ　前期/health_sci1B11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci1B11_Review',methods = ["post"])
def health_sci1B11_Review():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci1B11_mihyouka_Review", methods=["POST"])
def health_sci1B11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学１ｂ　前期/health_sci1B11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci1B11_video',methods =["post"])
def health_sci1B11_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci1B11_mihyouka_video',methods =["post"])
def health_sci1B11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/health_sci1B12")
def health_sci1B12():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学１ｂ　前期/health_sci1B12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci1B12_Review',methods = ["post"])
def health_sci1B12_Review():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci1B12_mihyouka_Review", methods=["POST"])
def health_sci1B12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学１ｂ　前期/health_sci1B12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci1B12_video',methods =["post"])
def health_sci1B12_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci1B12_mihyouka_video',methods =["post"])
def health_sci1B12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/health_sci1B13")
def health_sci1B13():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学１ｂ　前期/health_sci1B13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci1B13_Review',methods = ["post"])
def health_sci1B13_Review():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci1B13_mihyouka_Review", methods=["POST"])
def health_sci1B13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学１ｂ　前期/health_sci1B13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci1B13_video',methods =["post"])
def health_sci1B13_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci1B13_mihyouka_video',methods =["post"])
def health_sci1B13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/health_sci1B14")
def health_sci1B14():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学１ｂ　前期/health_sci1B14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci1B14_Review',methods = ["post"])
def health_sci1B14_Review():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci1B14_mihyouka_Review", methods=["POST"])
def health_sci1B14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学１ｂ　前期/health_sci1B14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci1B14_video',methods =["post"])
def health_sci1B14_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci1B14_mihyouka_video',methods =["post"])
def health_sci1B14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/health_sci1B15")
def health_sci1B15():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学１ｂ　前期/health_sci1B15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci1B15_Review',methods = ["post"])
def health_sci1B15_Review():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci1B15_mihyouka_Review", methods=["POST"])
def health_sci1B15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学１ｂ　前期/health_sci1B15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci1B15_video',methods =["post"])
def health_sci1B15_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci1B15_mihyouka_video',methods =["post"])
def health_sci1B15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学１ｂ　前期/健康科学１ｂ　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学１ｂ　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学１ｂ　前期/health_sci1B15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################健康科学２#############################
################################################################################################
@app.route("/health_sci2_")
def health_sci2_():
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/健康科学２/health_sci2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/health_sci2_1")
def health_sci2_1():
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学２/health_sci2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci2_1_Review',methods = ["post"])
def health_sci2_1_Review():
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学２/health_sci2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci2_1_mihyouka_Review", methods=["POST"])
def health_sci2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学２/health_sci2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci2_1_video',methods =["post"])
def health_sci2_1_video():
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学２/health_sci2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci2_1_mihyouka_video',methods =["post"])
def health_sci2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学２/health_sci2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/health_sci2_2")
def health_sci2_2():
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学２/health_sci2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci2_2_Review',methods = ["post"])
def health_sci2_2_Review():
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学２/health_sci2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci2_2_mihyouka_Review", methods=["POST"])
def health_sci2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学２/health_sci2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci2_2_video',methods =["post"])
def health_sci2_2_video():
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学２/health_sci2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci2_2_mihyouka_video',methods =["post"])
def health_sci2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学２/health_sci2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/health_sci2_3")
def health_sci2_3():
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学２/health_sci2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci2_3_Review',methods = ["post"])
def health_sci2_3_Review():
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学２/health_sci2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci2_3_mihyouka_Review", methods=["POST"])
def health_sci2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学２/health_sci2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci2_3_video',methods =["post"])
def health_sci2_3_video():
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学２/health_sci2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci2_3_mihyouka_video',methods =["post"])
def health_sci2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学２/health_sci2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/health_sci2_4")
def health_sci2_4():
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学２/health_sci2_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci2_4_Review',methods = ["post"])
def health_sci2_4_Review():
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学２/health_sci2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci2_4_mihyouka_Review", methods=["POST"])
def health_sci2_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学２/health_sci2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci2_4_video',methods =["post"])
def health_sci2_4_video():
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学２/health_sci2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci2_4_mihyouka_video',methods =["post"])
def health_sci2_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学２/健康科学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学２/health_sci2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################健康科学演習　前期#############################
################################################################################################
@app.route("/health_sci_exe1st")
def health_sci_exe1st():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/健康科学演習　前期/health_sci_exe1st_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/health_sci_exe1st1")
def health_sci_exe1st1():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学演習　前期/health_sci_exe1st1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci_exe1st1_Review',methods = ["post"])
def health_sci_exe1st1_Review():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci_exe1st1_mihyouka_Review", methods=["POST"])
def health_sci_exe1st1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学演習　前期/health_sci_exe1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci_exe1st1_video',methods =["post"])
def health_sci_exe1st1_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci_exe1st1_mihyouka_video',methods =["post"])
def health_sci_exe1st1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/health_sci_exe1st2")
def health_sci_exe1st2():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学演習　前期/health_sci_exe1st2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci_exe1st2_Review',methods = ["post"])
def health_sci_exe1st2_Review():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci_exe1st2_mihyouka_Review", methods=["POST"])
def health_sci_exe1st2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学演習　前期/health_sci_exe1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci_exe1st2_video',methods =["post"])
def health_sci_exe1st2_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci_exe1st2_mihyouka_video',methods =["post"])
def health_sci_exe1st2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/health_sci_exe1st3")
def health_sci_exe1st3():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学演習　前期/health_sci_exe1st3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci_exe1st3_Review',methods = ["post"])
def health_sci_exe1st3_Review():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci_exe1st3_mihyouka_Review", methods=["POST"])
def health_sci_exe1st3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学演習　前期/health_sci_exe1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci_exe1st3_video',methods =["post"])
def health_sci_exe1st3_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci_exe1st3_mihyouka_video',methods =["post"])
def health_sci_exe1st3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/health_sci_exe1st4")
def health_sci_exe1st4():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学演習　前期/health_sci_exe1st4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci_exe1st4_Review',methods = ["post"])
def health_sci_exe1st4_Review():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci_exe1st4_mihyouka_Review", methods=["POST"])
def health_sci_exe1st4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学演習　前期/health_sci_exe1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci_exe1st4_video',methods =["post"])
def health_sci_exe1st4_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci_exe1st4_mihyouka_video',methods =["post"])
def health_sci_exe1st4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/health_sci_exe1st5")
def health_sci_exe1st5():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学演習　前期/health_sci_exe1st5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci_exe1st5_Review',methods = ["post"])
def health_sci_exe1st5_Review():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci_exe1st5_mihyouka_Review", methods=["POST"])
def health_sci_exe1st5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学演習　前期/health_sci_exe1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci_exe1st5_video',methods =["post"])
def health_sci_exe1st5_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci_exe1st5_mihyouka_video',methods =["post"])
def health_sci_exe1st5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/health_sci_exe1st6")
def health_sci_exe1st6():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学演習　前期/health_sci_exe1st6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci_exe1st6_Review',methods = ["post"])
def health_sci_exe1st6_Review():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci_exe1st6_mihyouka_Review", methods=["POST"])
def health_sci_exe1st6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学演習　前期/health_sci_exe1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci_exe1st6_video',methods =["post"])
def health_sci_exe1st6_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci_exe1st6_mihyouka_video',methods =["post"])
def health_sci_exe1st6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/health_sci_exe1st7")
def health_sci_exe1st7():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学演習　前期/health_sci_exe1st7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci_exe1st7_Review',methods = ["post"])
def health_sci_exe1st7_Review():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci_exe1st7_mihyouka_Review", methods=["POST"])
def health_sci_exe1st7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学演習　前期/health_sci_exe1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci_exe1st7_video',methods =["post"])
def health_sci_exe1st7_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci_exe1st7_mihyouka_video',methods =["post"])
def health_sci_exe1st7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/health_sci_exe1st8")
def health_sci_exe1st8():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学演習　前期/health_sci_exe1st8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci_exe1st8_Review',methods = ["post"])
def health_sci_exe1st8_Review():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci_exe1st8_mihyouka_Review", methods=["POST"])
def health_sci_exe1st8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学演習　前期/health_sci_exe1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci_exe1st8_video',methods =["post"])
def health_sci_exe1st8_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci_exe1st8_mihyouka_video',methods =["post"])
def health_sci_exe1st8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/health_sci_exe1st9")
def health_sci_exe1st9():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学演習　前期/health_sci_exe1st9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci_exe1st9_Review',methods = ["post"])
def health_sci_exe1st9_Review():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci_exe1st9_mihyouka_Review", methods=["POST"])
def health_sci_exe1st9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学演習　前期/health_sci_exe1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci_exe1st9_video',methods =["post"])
def health_sci_exe1st9_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci_exe1st9_mihyouka_video',methods =["post"])
def health_sci_exe1st9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/health_sci_exe1st10")
def health_sci_exe1st10():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学演習　前期/health_sci_exe1st10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci_exe1st10_Review',methods = ["post"])
def health_sci_exe1st10_Review():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci_exe1st10_mihyouka_Review", methods=["POST"])
def health_sci_exe1st10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学演習　前期/health_sci_exe1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci_exe1st10_video',methods =["post"])
def health_sci_exe1st10_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci_exe1st10_mihyouka_video',methods =["post"])
def health_sci_exe1st10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/health_sci_exe1st11")
def health_sci_exe1st11():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学演習　前期/health_sci_exe1st11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci_exe1st11_Review',methods = ["post"])
def health_sci_exe1st11_Review():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci_exe1st11_mihyouka_Review", methods=["POST"])
def health_sci_exe1st11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学演習　前期/health_sci_exe1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci_exe1st11_video',methods =["post"])
def health_sci_exe1st11_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci_exe1st11_mihyouka_video',methods =["post"])
def health_sci_exe1st11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/health_sci_exe1st12")
def health_sci_exe1st12():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学演習　前期/health_sci_exe1st12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci_exe1st12_Review',methods = ["post"])
def health_sci_exe1st12_Review():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci_exe1st12_mihyouka_Review", methods=["POST"])
def health_sci_exe1st12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学演習　前期/health_sci_exe1st12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci_exe1st12_video',methods =["post"])
def health_sci_exe1st12_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci_exe1st12_mihyouka_video',methods =["post"])
def health_sci_exe1st12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/health_sci_exe1st13")
def health_sci_exe1st13():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学演習　前期/health_sci_exe1st13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci_exe1st13_Review',methods = ["post"])
def health_sci_exe1st13_Review():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci_exe1st13_mihyouka_Review", methods=["POST"])
def health_sci_exe1st13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学演習　前期/health_sci_exe1st13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci_exe1st13_video',methods =["post"])
def health_sci_exe1st13_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci_exe1st13_mihyouka_video',methods =["post"])
def health_sci_exe1st13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/health_sci_exe1st14")
def health_sci_exe1st14():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学演習　前期/health_sci_exe1st14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci_exe1st14_Review',methods = ["post"])
def health_sci_exe1st14_Review():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci_exe1st14_mihyouka_Review", methods=["POST"])
def health_sci_exe1st14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学演習　前期/health_sci_exe1st14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci_exe1st14_video',methods =["post"])
def health_sci_exe1st14_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci_exe1st14_mihyouka_video',methods =["post"])
def health_sci_exe1st14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/health_sci_exe1st15")
def health_sci_exe1st15():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/健康科学演習　前期/health_sci_exe1st15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/health_sci_exe1st15_Review',methods = ["post"])
def health_sci_exe1st15_Review():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/health_sci_exe1st15_mihyouka_Review", methods=["POST"])
def health_sci_exe1st15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/健康科学演習　前期/health_sci_exe1st15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/health_sci_exe1st15_video',methods =["post"])
def health_sci_exe1st15_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/health_sci_exe1st15_mihyouka_video',methods =["post"])
def health_sci_exe1st15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/健康科学演習　前期/健康科学演習　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/健康科学演習　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/健康科学演習　前期/health_sci_exe1st15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################国際関係論#############################
################################################################################################
@app.route("/inter_rela")
def inter_rela():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/国際関係論/inter_rela_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/inter_rela1")
def inter_rela1():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/国際関係論/inter_rela1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/inter_rela1_Review',methods = ["post"])
def inter_rela1_Review():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/inter_rela1_mihyouka_Review", methods=["POST"])
def inter_rela1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/国際関係論/inter_rela1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/inter_rela1_video',methods =["post"])
def inter_rela1_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/国際関係論/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/inter_rela1_mihyouka_video',methods =["post"])
def inter_rela1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/国際関係論/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/inter_rela2")
def inter_rela2():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/国際関係論/inter_rela2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/inter_rela2_Review',methods = ["post"])
def inter_rela2_Review():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/inter_rela2_mihyouka_Review", methods=["POST"])
def inter_rela2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/国際関係論/inter_rela2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/inter_rela2_video',methods =["post"])
def inter_rela2_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/国際関係論/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/inter_rela2_mihyouka_video',methods =["post"])
def inter_rela2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/国際関係論/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/inter_rela3")
def inter_rela3():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/国際関係論/inter_rela3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/inter_rela3_Review',methods = ["post"])
def inter_rela3_Review():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/inter_rela3_mihyouka_Review", methods=["POST"])
def inter_rela3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/国際関係論/inter_rela3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/inter_rela3_video',methods =["post"])
def inter_rela3_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/国際関係論/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/inter_rela3_mihyouka_video',methods =["post"])
def inter_rela3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/国際関係論/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/inter_rela4")
def inter_rela4():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/国際関係論/inter_rela4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/inter_rela4_Review',methods = ["post"])
def inter_rela4_Review():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/inter_rela4_mihyouka_Review", methods=["POST"])
def inter_rela4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/国際関係論/inter_rela4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/inter_rela4_video',methods =["post"])
def inter_rela4_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/国際関係論/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/inter_rela4_mihyouka_video',methods =["post"])
def inter_rela4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/国際関係論/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/inter_rela5")
def inter_rela5():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/国際関係論/inter_rela5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/inter_rela5_Review',methods = ["post"])
def inter_rela5_Review():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/inter_rela5_mihyouka_Review", methods=["POST"])
def inter_rela5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/国際関係論/inter_rela5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/inter_rela5_video',methods =["post"])
def inter_rela5_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/国際関係論/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/inter_rela5_mihyouka_video',methods =["post"])
def inter_rela5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/国際関係論/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/inter_rela6")
def inter_rela6():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/国際関係論/inter_rela6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/inter_rela6_Review',methods = ["post"])
def inter_rela6_Review():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/inter_rela6_mihyouka_Review", methods=["POST"])
def inter_rela6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/国際関係論/inter_rela6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/inter_rela6_video',methods =["post"])
def inter_rela6_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/国際関係論/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/inter_rela6_mihyouka_video',methods =["post"])
def inter_rela6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/国際関係論/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/inter_rela7")
def inter_rela7():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/国際関係論/inter_rela7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/inter_rela7_Review',methods = ["post"])
def inter_rela7_Review():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/inter_rela7_mihyouka_Review", methods=["POST"])
def inter_rela7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/国際関係論/inter_rela7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/inter_rela7_video',methods =["post"])
def inter_rela7_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/国際関係論/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/inter_rela7_mihyouka_video',methods =["post"])
def inter_rela7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/国際関係論/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/inter_rela8")
def inter_rela8():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/国際関係論/inter_rela8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/inter_rela8_Review',methods = ["post"])
def inter_rela8_Review():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/inter_rela8_mihyouka_Review", methods=["POST"])
def inter_rela8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/国際関係論/inter_rela8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/inter_rela8_video',methods =["post"])
def inter_rela8_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/国際関係論/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/inter_rela8_mihyouka_video',methods =["post"])
def inter_rela8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/国際関係論/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/inter_rela9")
def inter_rela9():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/国際関係論/inter_rela9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/inter_rela9_Review',methods = ["post"])
def inter_rela9_Review():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/inter_rela9_mihyouka_Review", methods=["POST"])
def inter_rela9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/国際関係論/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/国際関係論/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/国際関係論/inter_rela9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/inter_rela9_video',methods =["post"])
def inter_rela9_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/国際関係論/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/inter_rela9_mihyouka_video',methods =["post"])
def inter_rela9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/国際関係論/国際関係論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/国際関係論/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/国際関係論/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/国際関係論/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/国際関係論/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/国際関係論/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/国際関係論/inter_rela9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################社会学１　前期#############################
################################################################################################
@app.route("/sociology1_1st")
def sociology1_1st():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/社会学１　前期/sociology1_1st_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/sociology1_1st1")
def sociology1_1st1():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学１　前期/sociology1_1st1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology1_1st1_Review',methods = ["post"])
def sociology1_1st1_Review():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology1_1st1_mihyouka_Review", methods=["POST"])
def sociology1_1st1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学１　前期/sociology1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology1_1st1_video',methods =["post"])
def sociology1_1st1_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology1_1st1_mihyouka_video',methods =["post"])
def sociology1_1st1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/sociology1_1st2")
def sociology1_1st2():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学１　前期/sociology1_1st2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology1_1st2_Review',methods = ["post"])
def sociology1_1st2_Review():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology1_1st2_mihyouka_Review", methods=["POST"])
def sociology1_1st2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学１　前期/sociology1_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology1_1st2_video',methods =["post"])
def sociology1_1st2_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology1_1st2_mihyouka_video',methods =["post"])
def sociology1_1st2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/sociology1_1st3")
def sociology1_1st3():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学１　前期/sociology1_1st3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology1_1st3_Review',methods = ["post"])
def sociology1_1st3_Review():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology1_1st3_mihyouka_Review", methods=["POST"])
def sociology1_1st3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学１　前期/sociology1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology1_1st3_video',methods =["post"])
def sociology1_1st3_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology1_1st3_mihyouka_video',methods =["post"])
def sociology1_1st3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/sociology1_1st4")
def sociology1_1st4():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学１　前期/sociology1_1st4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology1_1st4_Review',methods = ["post"])
def sociology1_1st4_Review():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology1_1st4_mihyouka_Review", methods=["POST"])
def sociology1_1st4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学１　前期/sociology1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology1_1st4_video',methods =["post"])
def sociology1_1st4_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology1_1st4_mihyouka_video',methods =["post"])
def sociology1_1st4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/sociology1_1st5")
def sociology1_1st5():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学１　前期/sociology1_1st5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology1_1st5_Review',methods = ["post"])
def sociology1_1st5_Review():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology1_1st5_mihyouka_Review", methods=["POST"])
def sociology1_1st5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学１　前期/sociology1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology1_1st5_video',methods =["post"])
def sociology1_1st5_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology1_1st5_mihyouka_video',methods =["post"])
def sociology1_1st5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/sociology1_1st6")
def sociology1_1st6():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学１　前期/sociology1_1st6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology1_1st6_Review',methods = ["post"])
def sociology1_1st6_Review():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology1_1st6_mihyouka_Review", methods=["POST"])
def sociology1_1st6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学１　前期/sociology1_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology1_1st6_video',methods =["post"])
def sociology1_1st6_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology1_1st6_mihyouka_video',methods =["post"])
def sociology1_1st6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/sociology1_1st7")
def sociology1_1st7():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学１　前期/sociology1_1st7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology1_1st7_Review',methods = ["post"])
def sociology1_1st7_Review():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology1_1st7_mihyouka_Review", methods=["POST"])
def sociology1_1st7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学１　前期/sociology1_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology1_1st7_video',methods =["post"])
def sociology1_1st7_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology1_1st7_mihyouka_video',methods =["post"])
def sociology1_1st7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/sociology1_1st8")
def sociology1_1st8():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学１　前期/sociology1_1st8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology1_1st8_Review',methods = ["post"])
def sociology1_1st8_Review():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology1_1st8_mihyouka_Review", methods=["POST"])
def sociology1_1st8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学１　前期/sociology1_1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology1_1st8_video',methods =["post"])
def sociology1_1st8_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology1_1st8_mihyouka_video',methods =["post"])
def sociology1_1st8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/sociology1_1st9")
def sociology1_1st9():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学１　前期/sociology1_1st9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology1_1st9_Review',methods = ["post"])
def sociology1_1st9_Review():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology1_1st9_mihyouka_Review", methods=["POST"])
def sociology1_1st9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学１　前期/sociology1_1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology1_1st9_video',methods =["post"])
def sociology1_1st9_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology1_1st9_mihyouka_video',methods =["post"])
def sociology1_1st9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/sociology1_1st10")
def sociology1_1st10():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学１　前期/sociology1_1st10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology1_1st10_Review',methods = ["post"])
def sociology1_1st10_Review():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology1_1st10_mihyouka_Review", methods=["POST"])
def sociology1_1st10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学１　前期/sociology1_1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology1_1st10_video',methods =["post"])
def sociology1_1st10_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology1_1st10_mihyouka_video',methods =["post"])
def sociology1_1st10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/sociology1_1st11")
def sociology1_1st11():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学１　前期/sociology1_1st11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology1_1st11_Review',methods = ["post"])
def sociology1_1st11_Review():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology1_1st11_mihyouka_Review", methods=["POST"])
def sociology1_1st11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学１　前期/sociology1_1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology1_1st11_video',methods =["post"])
def sociology1_1st11_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology1_1st11_mihyouka_video',methods =["post"])
def sociology1_1st11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/sociology1_1st12")
def sociology1_1st12():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学１　前期/sociology1_1st12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology1_1st12_Review',methods = ["post"])
def sociology1_1st12_Review():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology1_1st12_mihyouka_Review", methods=["POST"])
def sociology1_1st12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学１　前期/sociology1_1st12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology1_1st12_video',methods =["post"])
def sociology1_1st12_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology1_1st12_mihyouka_video',methods =["post"])
def sociology1_1st12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/sociology1_1st13")
def sociology1_1st13():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学１　前期/sociology1_1st13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology1_1st13_Review',methods = ["post"])
def sociology1_1st13_Review():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology1_1st13_mihyouka_Review", methods=["POST"])
def sociology1_1st13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学１　前期/sociology1_1st13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology1_1st13_video',methods =["post"])
def sociology1_1st13_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology1_1st13_mihyouka_video',methods =["post"])
def sociology1_1st13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/sociology1_1st14")
def sociology1_1st14():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学１　前期/sociology1_1st14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology1_1st14_Review',methods = ["post"])
def sociology1_1st14_Review():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology1_1st14_mihyouka_Review", methods=["POST"])
def sociology1_1st14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学１　前期/sociology1_1st14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology1_1st14_video',methods =["post"])
def sociology1_1st14_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology1_1st14_mihyouka_video',methods =["post"])
def sociology1_1st14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/sociology1_1st15")
def sociology1_1st15():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学１　前期/sociology1_1st15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology1_1st15_Review',methods = ["post"])
def sociology1_1st15_Review():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology1_1st15_mihyouka_Review", methods=["POST"])
def sociology1_1st15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学１　前期/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学１　前期/sociology1_1st15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology1_1st15_video',methods =["post"])
def sociology1_1st15_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology1_1st15_mihyouka_video',methods =["post"])
def sociology1_1st15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学１　前期/社会学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学１　前期/sociology1_1st15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################社会学２#############################
################################################################################################
@app.route("/sociology2_")
def sociology2_():
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/社会学２/sociology2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/sociology2_1")
def sociology2_1():
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学２/sociology2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology2_1_Review',methods = ["post"])
def sociology2_1_Review():
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学２/sociology2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology2_1_mihyouka_Review", methods=["POST"])
def sociology2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学２/sociology2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology2_1_video',methods =["post"])
def sociology2_1_video():
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学２/sociology2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology2_1_mihyouka_video',methods =["post"])
def sociology2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学２/sociology2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/sociology2_2")
def sociology2_2():
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学２/sociology2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology2_2_Review',methods = ["post"])
def sociology2_2_Review():
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学２/sociology2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology2_2_mihyouka_Review", methods=["POST"])
def sociology2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学２/sociology2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology2_2_video',methods =["post"])
def sociology2_2_video():
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学２/sociology2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology2_2_mihyouka_video',methods =["post"])
def sociology2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学２/sociology2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/sociology2_3")
def sociology2_3():
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学２/sociology2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology2_3_Review',methods = ["post"])
def sociology2_3_Review():
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学２/sociology2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology2_3_mihyouka_Review", methods=["POST"])
def sociology2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学２/sociology2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology2_3_video',methods =["post"])
def sociology2_3_video():
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学２/sociology2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology2_3_mihyouka_video',methods =["post"])
def sociology2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学２/sociology2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/sociology2_4")
def sociology2_4():
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/社会学２/sociology2_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/sociology2_4_Review',methods = ["post"])
def sociology2_4_Review():
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/社会学２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/社会学２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学２/sociology2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/sociology2_4_mihyouka_Review", methods=["POST"])
def sociology2_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/社会学２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/社会学２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/社会学２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/社会学２/sociology2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/sociology2_4_video',methods =["post"])
def sociology2_4_video():
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/社会学２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/社会学２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学２/sociology2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/sociology2_4_mihyouka_video',methods =["post"])
def sociology2_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/社会学２/社会学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/社会学２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/社会学２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/社会学２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/社会学２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/社会学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/社会学２/sociology2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################情報システムと地球環境#############################
###############################################################################################
@app.route("/info_global")
def info_global():
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/情報システムと地球環境/info_global_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/info_global1")
def info_global1():
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システムと地球環境/info_global1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_global1_Review',methods = ["post"])
def info_global1_Review():
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システムと地球環境/info_global1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_global1_mihyouka_Review", methods=["POST"])
def info_global1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システムと地球環境/info_global1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_global1_video',methods =["post"])
def info_global1_video():
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システムと地球環境/info_global1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_global1_mihyouka_video',methods =["post"])
def info_global1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システムと地球環境/info_global1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/info_global2")
def info_global2():
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システムと地球環境/info_global2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_global2_Review',methods = ["post"])
def info_global2_Review():
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システムと地球環境/info_global2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_global2_mihyouka_Review", methods=["POST"])
def info_global2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システムと地球環境/info_global2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_global2_video',methods =["post"])
def info_global2_video():
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システムと地球環境/info_global2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_global2_mihyouka_video',methods =["post"])
def info_global2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システムと地球環境/info_global2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/info_global3")
def info_global3():
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システムと地球環境/info_global3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_global3_Review',methods = ["post"])
def info_global3_Review():
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システムと地球環境/info_global3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_global3_mihyouka_Review", methods=["POST"])
def info_global3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システムと地球環境/info_global3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_global3_video',methods =["post"])
def info_global3_video():
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システムと地球環境/info_global3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_global3_mihyouka_video',methods =["post"])
def info_global3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システムと地球環境/info_global3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/info_global4")
def info_global4():
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システムと地球環境/info_global4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_global4_Review',methods = ["post"])
def info_global4_Review():
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システムと地球環境/info_global4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_global4_mihyouka_Review", methods=["POST"])
def info_global4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システムと地球環境/info_global4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_global4_video',methods =["post"])
def info_global4_video():
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システムと地球環境/info_global4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_global4_mihyouka_video',methods =["post"])
def info_global4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システムと地球環境/情報システムと地球環境.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システムと地球環境/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システムと地球環境/info_global4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################情報システム工学概論#############################
################################################################################################
@app.route("/intro_info_sys")
def intro_info_sys():
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/情報システム工学概論/intro_info_sys_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/intro_info_sys1")
def intro_info_sys1():
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学概論/intro_info_sys1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/intro_info_sys1_Review',methods = ["post"])
def intro_info_sys1_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学概論/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学概論/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学概論/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学概論/intro_info_sys1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/intro_info_sys1_mihyouka_Review", methods=["POST"])
def intro_info_sys1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学概論/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学概論/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学概論/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学概論/intro_info_sys1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/intro_info_sys1_video',methods =["post"])
def intro_info_sys1_video():
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学概論/intro_info_sys1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/intro_info_sys1_mihyouka_video',methods =["post"])
def intro_info_sys1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学概論/intro_info_sys1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/intro_info_sys2")
def intro_info_sys2():
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学概論/intro_info_sys2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/intro_info_sys2_Review',methods = ["post"])
def intro_info_sys2_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学概論/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学概論/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学概論/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学概論/intro_info_sys2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/intro_info_sys2_mihyouka_Review", methods=["POST"])
def intro_info_sys2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学概論/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学概論/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学概論/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学概論/intro_info_sys2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/intro_info_sys2_video',methods =["post"])
def intro_info_sys2_video():
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学概論/intro_info_sys2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/intro_info_sys2_mihyouka_video',methods =["post"])
def intro_info_sys2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学概論/intro_info_sys2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/intro_info_sys3")
def intro_info_sys3():
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学概論/intro_info_sys3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/intro_info_sys3_Review',methods = ["post"])
def intro_info_sys3_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学概論/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学概論/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学概論/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学概論/intro_info_sys3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/intro_info_sys3_mihyouka_Review", methods=["POST"])
def intro_info_sys3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学概論/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学概論/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学概論/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学概論/intro_info_sys3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/intro_info_sys3_video',methods =["post"])
def intro_info_sys3_video():
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学概論/intro_info_sys3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/intro_info_sys3_mihyouka_video',methods =["post"])
def intro_info_sys3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学概論/intro_info_sys3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/intro_info_sys4")
def intro_info_sys4():
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学概論/intro_info_sys4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/intro_info_sys4_Review',methods = ["post"])
def intro_info_sys4_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学概論/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学概論/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学概論/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学概論/intro_info_sys4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/intro_info_sys4_mihyouka_Review", methods=["POST"])
def intro_info_sys4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学概論/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学概論/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学概論/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学概論/intro_info_sys4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/intro_info_sys4_video',methods =["post"])
def intro_info_sys4_video():
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学概論/intro_info_sys4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/intro_info_sys4_mihyouka_video',methods =["post"])
def intro_info_sys4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学概論/情報システム工学概論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学概論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学概論/intro_info_sys4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################情報システム工学実験１############################
################################################################################################
@app.route("/info_sys_exp1_")
def info_sys_exp1_():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/情報システム工学実験１/info_sys_exp1__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/info_sys_exp1_1")
def info_sys_exp1_1():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学実験１/info_sys_exp1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_sys_exp1_1_Review',methods = ["post"])
def info_sys_exp1_1_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_sys_exp1_1_mihyouka_Review", methods=["POST"])
def info_sys_exp1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学実験１/info_sys_exp1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_sys_exp1_1_video',methods =["post"])
def info_sys_exp1_1_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_sys_exp1_1_mihyouka_video',methods =["post"])
def info_sys_exp1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/info_sys_exp1_2")
def info_sys_exp1_2():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学実験１/info_sys_exp1_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_sys_exp1_2_Review',methods = ["post"])
def info_sys_exp1_2_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_sys_exp1_2_mihyouka_Review", methods=["POST"])
def info_sys_exp1_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学実験１/info_sys_exp1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_sys_exp1_2_video',methods =["post"])
def info_sys_exp1_2_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_sys_exp1_2_mihyouka_video',methods =["post"])
def info_sys_exp1_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/info_sys_exp1_3")
def info_sys_exp1_3():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学実験１/info_sys_exp1_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_sys_exp1_3_Review',methods = ["post"])
def info_sys_exp1_3_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_sys_exp1_3_mihyouka_Review", methods=["POST"])
def info_sys_exp1_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学実験１/info_sys_exp1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_sys_exp1_3_video',methods =["post"])
def info_sys_exp1_3_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_sys_exp1_3_mihyouka_video',methods =["post"])
def info_sys_exp1_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/info_sys_exp1_4")
def info_sys_exp1_4():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学実験１/info_sys_exp1_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_sys_exp1_4_Review',methods = ["post"])
def info_sys_exp1_4_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_sys_exp1_4_mihyouka_Review", methods=["POST"])
def info_sys_exp1_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学実験１/info_sys_exp1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_sys_exp1_4_video',methods =["post"])
def info_sys_exp1_4_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_sys_exp1_4_mihyouka_video',methods =["post"])
def info_sys_exp1_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/info_sys_exp1_5")
def info_sys_exp1_5():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学実験１/info_sys_exp1_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_sys_exp1_5_Review',methods = ["post"])
def info_sys_exp1_5_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_sys_exp1_5_mihyouka_Review", methods=["POST"])
def info_sys_exp1_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学実験１/info_sys_exp1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_sys_exp1_5_video',methods =["post"])
def info_sys_exp1_5_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_sys_exp1_5_mihyouka_video',methods =["post"])
def info_sys_exp1_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/info_sys_exp1_6")
def info_sys_exp1_6():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学実験１/info_sys_exp1_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_sys_exp1_6_Review',methods = ["post"])
def info_sys_exp1_6_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_sys_exp1_6_mihyouka_Review", methods=["POST"])
def info_sys_exp1_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学実験１/info_sys_exp1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_sys_exp1_6_video',methods =["post"])
def info_sys_exp1_6_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_sys_exp1_6_mihyouka_video',methods =["post"])
def info_sys_exp1_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験１/情報システム工学実験１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験１/info_sys_exp1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################情報システム工学実験２############################
################################################################################################
@app.route("/info_sys_exp2_")
def info_sys_exp2_():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/情報システム工学実験２/info_sys_exp2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/info_sys_exp2_1")
def info_sys_exp2_1():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学実験２/info_sys_exp2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_sys_exp2_1_Review',methods = ["post"])
def info_sys_exp2_1_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験２/info_sys_exp2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_sys_exp2_1_mihyouka_Review", methods=["POST"])
def info_sys_exp2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学実験２/info_sys_exp2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_sys_exp2_1_video',methods =["post"])
def info_sys_exp2_1_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験２/info_sys_exp2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_sys_exp2_1_mihyouka_video',methods =["post"])
def info_sys_exp2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験２/info_sys_exp2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/info_sys_exp2_2")
def info_sys_exp2_2():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学実験２/info_sys_exp2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_sys_exp2_2_Review',methods = ["post"])
def info_sys_exp2_2_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験２/info_sys_exp2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_sys_exp2_2_mihyouka_Review", methods=["POST"])
def info_sys_exp2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学実験２/info_sys_exp2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_sys_exp2_2_video',methods =["post"])
def info_sys_exp2_2_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験２/info_sys_exp2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_sys_exp2_2_mihyouka_video',methods =["post"])
def info_sys_exp2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験２/info_sys_exp2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/info_sys_exp2_3")
def info_sys_exp2_3():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学実験２/info_sys_exp2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_sys_exp2_3_Review',methods = ["post"])
def info_sys_exp2_3_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験２/info_sys_exp2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_sys_exp2_3_mihyouka_Review", methods=["POST"])
def info_sys_exp2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学実験２/info_sys_exp2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_sys_exp2_3_video',methods =["post"])
def info_sys_exp2_3_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験２/info_sys_exp2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_sys_exp2_3_mihyouka_video',methods =["post"])
def info_sys_exp2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験２/info_sys_exp2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/info_sys_exp2_4")
def info_sys_exp2_4():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学実験２/info_sys_exp2_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_sys_exp2_4_Review',methods = ["post"])
def info_sys_exp2_4_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験２/info_sys_exp2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_sys_exp2_4_mihyouka_Review", methods=["POST"])
def info_sys_exp2_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学実験２/info_sys_exp2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_sys_exp2_4_video',methods =["post"])
def info_sys_exp2_4_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験２/info_sys_exp2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_sys_exp2_4_mihyouka_video',methods =["post"])
def info_sys_exp2_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験２/info_sys_exp2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/info_sys_exp2_5")
def info_sys_exp2_5():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学実験２/info_sys_exp2_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_sys_exp2_5_Review',methods = ["post"])
def info_sys_exp2_5_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験２/info_sys_exp2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_sys_exp2_5_mihyouka_Review", methods=["POST"])
def info_sys_exp2_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学実験２/info_sys_exp2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_sys_exp2_5_video',methods =["post"])
def info_sys_exp2_5_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験２/info_sys_exp2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_sys_exp2_5_mihyouka_video',methods =["post"])
def info_sys_exp2_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学実験２/情報システム工学実験２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学実験２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学実験２/info_sys_exp2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################情報システム工学特別講義############################
################################################################################################
@app.route("/special_info")
def special_info():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/情報システム工学特別講義/special_info_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/special_info1")
def special_info1():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学特別講義/special_info1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/special_info1_Review',methods = ["post"])
def special_info1_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/special_info1_mihyouka_Review", methods=["POST"])
def special_info1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学特別講義/special_info1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/special_info1_video',methods =["post"])
def special_info1_video():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/special_info1_mihyouka_video',methods =["post"])
def special_info1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/special_info2")
def special_info2():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学特別講義/special_info2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/special_info2_Review',methods = ["post"])
def special_info2_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/special_info2_mihyouka_Review", methods=["POST"])
def special_info2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学特別講義/special_info2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/special_info2_video',methods =["post"])
def special_info2_video():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/special_info2_mihyouka_video',methods =["post"])
def special_info2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/special_info3")
def special_info3():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学特別講義/special_info3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/special_info3_Review',methods = ["post"])
def special_info3_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/special_info3_mihyouka_Review", methods=["POST"])
def special_info3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学特別講義/special_info3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/special_info3_video',methods =["post"])
def special_info3_video():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/special_info3_mihyouka_video',methods =["post"])
def special_info3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/special_info4")
def special_info4():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学特別講義/special_info4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/special_info4_Review',methods = ["post"])
def special_info4_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/special_info4_mihyouka_Review", methods=["POST"])
def special_info4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学特別講義/special_info4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/special_info4_video',methods =["post"])
def special_info4_video():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/special_info4_mihyouka_video',methods =["post"])
def special_info4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/special_info5")
def special_info5():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学特別講義/special_info5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/special_info5_Review',methods = ["post"])
def special_info5_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/special_info5_mihyouka_Review", methods=["POST"])
def special_info5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学特別講義/special_info5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/special_info5_video',methods =["post"])
def special_info5_video():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/special_info5_mihyouka_video',methods =["post"])
def special_info5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/special_info6")
def special_info6():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報システム工学特別講義/special_info6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/special_info6_Review',methods = ["post"])
def special_info6_Review():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/special_info6_mihyouka_Review", methods=["POST"])
def special_info6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報システム工学特別講義/special_info6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/special_info6_video',methods =["post"])
def special_info6_video():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/special_info6_mihyouka_video',methods =["post"])
def special_info6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報システム工学特別講義/情報システム工学特別講義.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報システム工学特別講義/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報システム工学特別講義/special_info6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################情報数学１############################
################################################################################################
@app.route("/info_math1_")
def info_math1_():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/情報数学１/info_math1__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/info_math1_1")
def info_math1_1():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報数学１/info_math1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_math1_1_Review',methods = ["post"])
def info_math1_1_Review():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_math1_1_mihyouka_Review", methods=["POST"])
def info_math1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報数学１/info_math1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_math1_1_video',methods =["post"])
def info_math1_1_video():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報数学１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報数学１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_math1_1_mihyouka_video',methods =["post"])
def info_math1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報数学１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報数学１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/info_math1_2")
def info_math1_2():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報数学１/info_math1_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_math1_2_Review',methods = ["post"])
def info_math1_2_Review():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学１/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_math1_2_mihyouka_Review", methods=["POST"])
def info_math1_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学１/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報数学１/info_math1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_math1_2_video',methods =["post"])
def info_math1_2_video():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報数学１/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報数学１/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_math1_2_mihyouka_video',methods =["post"])
def info_math1_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報数学１/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報数学１/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/info_math1_3")
def info_math1_3():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報数学１/info_math1_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_math1_3_Review',methods = ["post"])
def info_math1_3_Review():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学１/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_math1_3_mihyouka_Review", methods=["POST"])
def info_math1_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学１/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報数学１/info_math1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_math1_3_video',methods =["post"])
def info_math1_3_video():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報数学１/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報数学１/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_math1_3_mihyouka_video',methods =["post"])
def info_math1_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報数学１/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報数学１/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/info_math1_4")
def info_math1_4():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報数学１/info_math1_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_math1_4_Review',methods = ["post"])
def info_math1_4_Review():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学１/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_math1_4_mihyouka_Review", methods=["POST"])
def info_math1_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学１/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報数学１/info_math1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_math1_4_video',methods =["post"])
def info_math1_4_video():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報数学１/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報数学１/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_math1_4_mihyouka_video',methods =["post"])
def info_math1_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報数学１/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報数学１/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/info_math1_5")
def info_math1_5():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報数学１/info_math1_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_math1_5_Review',methods = ["post"])
def info_math1_5_Review():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学１/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_math1_5_mihyouka_Review", methods=["POST"])
def info_math1_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学１/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報数学１/info_math1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_math1_5_video',methods =["post"])
def info_math1_5_video():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報数学１/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報数学１/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_math1_5_mihyouka_video',methods =["post"])
def info_math1_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報数学１/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報数学１/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/info_math1_6")
def info_math1_6():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報数学１/info_math1_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_math1_6_Review',methods = ["post"])
def info_math1_6_Review():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学１/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_math1_6_mihyouka_Review", methods=["POST"])
def info_math1_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学１/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報数学１/info_math1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_math1_6_video',methods =["post"])
def info_math1_6_video():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報数学１/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報数学１/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学１/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_math1_6_mihyouka_video',methods =["post"])
def info_math1_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報数学１/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報数学１/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学１/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/info_math1_7")
def info_math1_7():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報数学１/info_math1_7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_math1_7_Review',methods = ["post"])
def info_math1_7_Review():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学１/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_math1_7_mihyouka_Review", methods=["POST"])
def info_math1_7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学１/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報数学１/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報数学１/info_math1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_math1_7_video',methods =["post"])
def info_math1_7_video():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報数学１/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報数学１/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学１/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_math1_7_mihyouka_video',methods =["post"])
def info_math1_7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報数学１/情報数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報数学１/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報数学１/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報数学１/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学１/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学１/info_math1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################情報数学２############################
################################################################################################
@app.route("/info_math2_")
def info_math2_():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/情報数学２/info_math2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/info_math2_1")
def info_math2_1():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報数学２/info_math2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_math2_1_Review',methods = ["post"])
def info_math2_1_Review():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_math2_1_mihyouka_Review", methods=["POST"])
def info_math2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報数学２/info_math2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_math2_1_video',methods =["post"])
def info_math2_1_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報数学２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_math2_1_mihyouka_video',methods =["post"])
def info_math2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報数学２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/info_math2_2")
def info_math2_2():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報数学２/info_math2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_math2_2_Review',methods = ["post"])
def info_math2_2_Review():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_math2_2_mihyouka_Review", methods=["POST"])
def info_math2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報数学２/info_math2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_math2_2_video',methods =["post"])
def info_math2_2_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報数学２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_math2_2_mihyouka_video',methods =["post"])
def info_math2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報数学２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/info_math2_3")
def info_math2_3():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報数学２/info_math2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_math2_3_Review',methods = ["post"])
def info_math2_3_Review():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_math2_3_mihyouka_Review", methods=["POST"])
def info_math2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報数学２/info_math2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_math2_3_video',methods =["post"])
def info_math2_3_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報数学２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_math2_3_mihyouka_video',methods =["post"])
def info_math2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報数学２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/info_math2_4")
def info_math2_4():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報数学２/info_math2_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_math2_4_Review',methods = ["post"])
def info_math2_4_Review():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_math2_4_mihyouka_Review", methods=["POST"])
def info_math2_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報数学２/info_math2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_math2_4_video',methods =["post"])
def info_math2_4_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報数学２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_math2_4_mihyouka_video',methods =["post"])
def info_math2_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報数学２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/info_math2_5")
def info_math2_5():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報数学２/info_math2_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_math2_5_Review',methods = ["post"])
def info_math2_5_Review():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_math2_5_mihyouka_Review", methods=["POST"])
def info_math2_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報数学２/info_math2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_math2_5_video',methods =["post"])
def info_math2_5_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報数学２/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_math2_5_mihyouka_video',methods =["post"])
def info_math2_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報数学２/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/info_math2_6")
def info_math2_6():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報数学２/info_math2_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_math2_6_Review',methods = ["post"])
def info_math2_6_Review():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_math2_6_mihyouka_Review", methods=["POST"])
def info_math2_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報数学２/info_math2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_math2_6_video',methods =["post"])
def info_math2_6_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報数学２/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_math2_6_mihyouka_video',methods =["post"])
def info_math2_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報数学２/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/info_math2_7")
def info_math2_7():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報数学２/info_math2_7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_math2_7_Review',methods = ["post"])
def info_math2_7_Review():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_math2_7_mihyouka_Review", methods=["POST"])
def info_math2_7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報数学２/info_math2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_math2_7_video',methods =["post"])
def info_math2_7_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報数学２/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_math2_7_mihyouka_video',methods =["post"])
def info_math2_7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報数学２/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/info_math2_8")
def info_math2_8():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報数学２/info_math2_8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_math2_8_Review',methods = ["post"])
def info_math2_8_Review():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_math2_8_mihyouka_Review", methods=["POST"])
def info_math2_8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報数学２/info_math2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_math2_8_video',methods =["post"])
def info_math2_8_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報数学２/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_math2_8_mihyouka_video',methods =["post"])
def info_math2_8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報数学２/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/info_math2_9")
def info_math2_9():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報数学２/info_math2_9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_math2_9_Review',methods = ["post"])
def info_math2_9_Review():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_math2_9_mihyouka_Review", methods=["POST"])
def info_math2_9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報数学２/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報数学２/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報数学２/info_math2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_math2_9_video',methods =["post"])
def info_math2_9_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報数学２/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_math2_9_mihyouka_video',methods =["post"])
def info_math2_9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報数学２/情報数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報数学２/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報数学２/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報数学２/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報数学２/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報数学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報数学２/info_math2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################情報理論############################
################################################################################################
@app.route("/info_theo")
def info_theo():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/情報理論/info_theo_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/info_theo1")
def info_theo1():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報理論/info_theo1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_theo1_Review',methods = ["post"])
def info_theo1_Review():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報理論/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報理論/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報理論/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_theo1_mihyouka_Review", methods=["POST"])
def info_theo1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報理論/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報理論/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報理論/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報理論/info_theo1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_theo1_video',methods =["post"])
def info_theo1_video():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報理論/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報理論/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報理論/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_theo1_mihyouka_video',methods =["post"])
def info_theo1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報理論/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報理論/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報理論/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/info_theo2")
def info_theo2():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報理論/info_theo2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_theo2_Review',methods = ["post"])
def info_theo2_Review():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報理論/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報理論/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報理論/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_theo2_mihyouka_Review", methods=["POST"])
def info_theo2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報理論/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報理論/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報理論/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報理論/info_theo2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_theo2_video',methods =["post"])
def info_theo2_video():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報理論/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報理論/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報理論/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_theo2_mihyouka_video',methods =["post"])
def info_theo2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報理論/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報理論/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報理論/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/info_theo3")
def info_theo3():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報理論/info_theo3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_theo3_Review',methods = ["post"])
def info_theo3_Review():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報理論/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報理論/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報理論/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_theo3_mihyouka_Review", methods=["POST"])
def info_theo3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報理論/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報理論/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報理論/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報理論/info_theo3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_theo3_video',methods =["post"])
def info_theo3_video():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報理論/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報理論/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報理論/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_theo3_mihyouka_video',methods =["post"])
def info_theo3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報理論/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報理論/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報理論/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/info_theo4")
def info_theo4():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報理論/info_theo4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_theo4_Review',methods = ["post"])
def info_theo4_Review():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報理論/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報理論/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報理論/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_theo4_mihyouka_Review", methods=["POST"])
def info_theo4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報理論/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報理論/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報理論/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報理論/info_theo4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_theo4_video',methods =["post"])
def info_theo4_video():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報理論/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報理論/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報理論/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_theo4_mihyouka_video',methods =["post"])
def info_theo4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報理論/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報理論/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報理論/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/info_theo5")
def info_theo5():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報理論/info_theo5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_theo5_Review',methods = ["post"])
def info_theo5_Review():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報理論/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報理論/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報理論/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_theo5_mihyouka_Review", methods=["POST"])
def info_theo5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報理論/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報理論/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報理論/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報理論/info_theo5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_theo5_video',methods =["post"])
def info_theo5_video():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報理論/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報理論/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報理論/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_theo5_mihyouka_video',methods =["post"])
def info_theo5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報理論/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報理論/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報理論/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/info_theo6")
def info_theo6():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/情報理論/info_theo6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/info_theo6_Review',methods = ["post"])
def info_theo6_Review():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/情報理論/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報理論/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/情報理論/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/info_theo6_mihyouka_Review", methods=["POST"])
def info_theo6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/情報理論/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/情報理論/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/情報理論/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/情報理論/info_theo6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/info_theo6_video',methods =["post"])
def info_theo6_video():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/情報理論/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/情報理論/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報理論/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/info_theo6_mihyouka_video',methods =["post"])
def info_theo6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/情報理論/情報理論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/情報理論/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/情報理論/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/情報理論/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/情報理論/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/情報理論/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/情報理論/info_theo6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################心理学１　前期############################
################################################################################################
@app.route("/psycho1_1st")
def psycho1_1st():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/心理学１　前期/psycho1_1st_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/psycho1_1st1")
def psycho1_1st1():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学１　前期/psycho1_1st1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho1_1st1_Review',methods = ["post"])
def psycho1_1st1_Review():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho1_1st1_mihyouka_Review", methods=["POST"])
def psycho1_1st1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学１　前期/psycho1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho1_1st1_video',methods =["post"])
def psycho1_1st1_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho1_1st1_mihyouka_video',methods =["post"])
def psycho1_1st1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/psycho1_1st2")
def psycho1_1st2():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学１　前期/psycho1_1st2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho1_1st2_Review',methods = ["post"])
def psycho1_1st2_Review():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho1_1st2_mihyouka_Review", methods=["POST"])
def psycho1_1st2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学１　前期/psycho1_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho1_1st2_video',methods =["post"])
def psycho1_1st2_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho1_1st2_mihyouka_video',methods =["post"])
def psycho1_1st2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/psycho1_1st3")
def psycho1_1st3():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学１　前期/psycho1_1st3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho1_1st3_Review',methods = ["post"])
def psycho1_1st3_Review():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho1_1st3_mihyouka_Review", methods=["POST"])
def psycho1_1st3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学１　前期/psycho1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho1_1st3_video',methods =["post"])
def psycho1_1st3_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho1_1st3_mihyouka_video',methods =["post"])
def psycho1_1st3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/psycho1_1st4")
def psycho1_1st4():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学１　前期/psycho1_1st4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho1_1st4_Review',methods = ["post"])
def psycho1_1st4_Review():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho1_1st4_mihyouka_Review", methods=["POST"])
def psycho1_1st4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学１　前期/psycho1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho1_1st4_video',methods =["post"])
def psycho1_1st4_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho1_1st4_mihyouka_video',methods =["post"])
def psycho1_1st4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/psycho1_1st5")
def psycho1_1st5():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学１　前期/psycho1_1st5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho1_1st5_Review',methods = ["post"])
def psycho1_1st5_Review():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho1_1st5_mihyouka_Review", methods=["POST"])
def psycho1_1st5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学１　前期/psycho1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho1_1st5_video',methods =["post"])
def psycho1_1st5_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho1_1st5_mihyouka_video',methods =["post"])
def psycho1_1st5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/psycho1_1st6")
def psycho1_1st6():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学１　前期/psycho1_1st6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho1_1st6_Review',methods = ["post"])
def psycho1_1st6_Review():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho1_1st6_mihyouka_Review", methods=["POST"])
def psycho1_1st6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学１　前期/psycho1_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho1_1st6_video',methods =["post"])
def psycho1_1st6_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho1_1st6_mihyouka_video',methods =["post"])
def psycho1_1st6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/psycho1_1st7")
def psycho1_1st7():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学１　前期/psycho1_1st7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho1_1st7_Review',methods = ["post"])
def psycho1_1st7_Review():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho1_1st7_mihyouka_Review", methods=["POST"])
def psycho1_1st7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学１　前期/psycho1_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho1_1st7_video',methods =["post"])
def psycho1_1st7_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho1_1st7_mihyouka_video',methods =["post"])
def psycho1_1st7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/psycho1_1st8")
def psycho1_1st8():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学１　前期/psycho1_1st8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho1_1st8_Review',methods = ["post"])
def psycho1_1st8_Review():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho1_1st8_mihyouka_Review", methods=["POST"])
def psycho1_1st8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学１　前期/psycho1_1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho1_1st8_video',methods =["post"])
def psycho1_1st8_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho1_1st8_mihyouka_video',methods =["post"])
def psycho1_1st8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/psycho1_1st9")
def psycho1_1st9():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学１　前期/psycho1_1st9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho1_1st9_Review',methods = ["post"])
def psycho1_1st9_Review():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho1_1st9_mihyouka_Review", methods=["POST"])
def psycho1_1st9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学１　前期/psycho1_1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho1_1st9_video',methods =["post"])
def psycho1_1st9_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho1_1st9_mihyouka_video',methods =["post"])
def psycho1_1st9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/psycho1_1st10")
def psycho1_1st10():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学１　前期/psycho1_1st10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho1_1st10_Review',methods = ["post"])
def psycho1_1st10_Review():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho1_1st10_mihyouka_Review", methods=["POST"])
def psycho1_1st10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学１　前期/psycho1_1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho1_1st10_video',methods =["post"])
def psycho1_1st10_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho1_1st10_mihyouka_video',methods =["post"])
def psycho1_1st10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/psycho1_1st11")
def psycho1_1st11():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学１　前期/psycho1_1st11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho1_1st11_Review',methods = ["post"])
def psycho1_1st11_Review():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho1_1st11_mihyouka_Review", methods=["POST"])
def psycho1_1st11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学１　前期/psycho1_1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho1_1st11_video',methods =["post"])
def psycho1_1st11_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho1_1st11_mihyouka_video',methods =["post"])
def psycho1_1st11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/psycho1_1st12")
def psycho1_1st12():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学１　前期/psycho1_1st12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho1_1st12_Review',methods = ["post"])
def psycho1_1st12_Review():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho1_1st12_mihyouka_Review", methods=["POST"])
def psycho1_1st12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学１　前期/psycho1_1st12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho1_1st12_video',methods =["post"])
def psycho1_1st12_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho1_1st12_mihyouka_video',methods =["post"])
def psycho1_1st12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/psycho1_1st13")
def psycho1_1st13():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学１　前期/psycho1_1st13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho1_1st13_Review',methods = ["post"])
def psycho1_1st13_Review():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho1_1st13_mihyouka_Review", methods=["POST"])
def psycho1_1st13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学１　前期/psycho1_1st13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho1_1st13_video',methods =["post"])
def psycho1_1st13_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho1_1st13_mihyouka_video',methods =["post"])
def psycho1_1st13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/psycho1_1st14")
def psycho1_1st14():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学１　前期/psycho1_1st14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho1_1st14_Review',methods = ["post"])
def psycho1_1st14_Review():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho1_1st14_mihyouka_Review", methods=["POST"])
def psycho1_1st14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学１　前期/psycho1_1st14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho1_1st14_video',methods =["post"])
def psycho1_1st14_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho1_1st14_mihyouka_video',methods =["post"])
def psycho1_1st14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/psycho1_1st15")
def psycho1_1st15():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学１　前期/psycho1_1st15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho1_1st15_Review',methods = ["post"])
def psycho1_1st15_Review():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho1_1st15_mihyouka_Review", methods=["POST"])
def psycho1_1st15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学１　前期/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学１　前期/psycho1_1st15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho1_1st15_video',methods =["post"])
def psycho1_1st15_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho1_1st15_mihyouka_video',methods =["post"])
def psycho1_1st15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学１　前期/心理学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学１　前期/psycho1_1st15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################心理学２　前期############################
################################################################################################
@app.route("/psycho2_1st")
def psycho2_1st():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/心理学２　前期/psycho2_1st_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/psycho2_1st1")
def psycho2_1st1():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学２　前期/psycho2_1st1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho2_1st1_Review',methods = ["post"])
def psycho2_1st1_Review():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho2_1st1_mihyouka_Review", methods=["POST"])
def psycho2_1st1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学２　前期/psycho2_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho2_1st1_video',methods =["post"])
def psycho2_1st1_video():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho2_1st1_mihyouka_video',methods =["post"])
def psycho2_1st1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/psycho2_1st2")
def psycho2_1st2():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学２　前期/psycho2_1st2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho2_1st2_Review',methods = ["post"])
def psycho2_1st2_Review():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho2_1st2_mihyouka_Review", methods=["POST"])
def psycho2_1st2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学２　前期/psycho2_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho2_1st2_video',methods =["post"])
def psycho2_1st2_video():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho2_1st2_mihyouka_video',methods =["post"])
def psycho2_1st2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/psycho2_1st3")
def psycho2_1st3():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学２　前期/psycho2_1st3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho2_1st3_Review',methods = ["post"])
def psycho2_1st3_Review():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho2_1st3_mihyouka_Review", methods=["POST"])
def psycho2_1st3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学２　前期/psycho2_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho2_1st3_video',methods =["post"])
def psycho2_1st3_video():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho2_1st3_mihyouka_video',methods =["post"])
def psycho2_1st3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/psycho2_1st4")
def psycho2_1st4():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学２　前期/psycho2_1st4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho2_1st4_Review',methods = ["post"])
def psycho2_1st4_Review():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho2_1st4_mihyouka_Review", methods=["POST"])
def psycho2_1st4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学２　前期/psycho2_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho2_1st4_video',methods =["post"])
def psycho2_1st4_video():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho2_1st4_mihyouka_video',methods =["post"])
def psycho2_1st4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/psycho2_1st5")
def psycho2_1st5():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学２　前期/psycho2_1st5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho2_1st5_Review',methods = ["post"])
def psycho2_1st5_Review():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho2_1st5_mihyouka_Review", methods=["POST"])
def psycho2_1st5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学２　前期/psycho2_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho2_1st5_video',methods =["post"])
def psycho2_1st5_video():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho2_1st5_mihyouka_video',methods =["post"])
def psycho2_1st5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/psycho2_1st6")
def psycho2_1st6():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/心理学２　前期/psycho2_1st6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/psycho2_1st6_Review',methods = ["post"])
def psycho2_1st6_Review():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/psycho2_1st6_mihyouka_Review", methods=["POST"])
def psycho2_1st6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/心理学２　前期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/心理学２　前期/psycho2_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/psycho2_1st6_video',methods =["post"])
def psycho2_1st6_video():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/psycho2_1st6_mihyouka_video',methods =["post"])
def psycho2_1st6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/心理学２　前期/心理学２　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/心理学２　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/心理学２　前期/psycho2_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################数学１############################
################################################################################################
@app.route("/math1_")
def math1_():
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/数学１/math1__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/math1_1")
def math1_1():
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数学１/math1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/math1_1_Review',methods = ["post"])
def math1_1_Review():
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数学１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数学１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学１/math1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/math1_1_mihyouka_Review", methods=["POST"])
def math1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数学１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数学１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数学１/math1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/math1_1_video',methods =["post"])
def math1_1_video():
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数学１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数学１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学１/math1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/math1_1_mihyouka_video',methods =["post"])
def math1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数学１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数学１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学１/math1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/math1_2")
def math1_2():
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数学１/math1_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/math1_2_Review',methods = ["post"])
def math1_2_Review():
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数学１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学１/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数学１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学１/math1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/math1_2_mihyouka_Review", methods=["POST"])
def math1_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数学１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学１/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数学１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数学１/math1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/math1_2_video',methods =["post"])
def math1_2_video():
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数学１/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数学１/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学１/math1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/math1_2_mihyouka_video',methods =["post"])
def math1_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数学１/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数学１/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学１/math1_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/math1_3")
def math1_3():
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数学１/math1_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/math1_3_Review',methods = ["post"])
def math1_3_Review():
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数学１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学１/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数学１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学１/math1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/math1_3_mihyouka_Review", methods=["POST"])
def math1_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数学１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学１/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数学１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数学１/math1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/math1_3_video',methods =["post"])
def math1_3_video():
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数学１/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数学１/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学１/math1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/math1_3_mihyouka_video',methods =["post"])
def math1_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数学１/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数学１/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学１/math1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/math1_4")
def math1_4():
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数学１/math1_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/math1_4_Review',methods = ["post"])
def math1_4_Review():
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数学１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学１/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数学１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学１/math1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/math1_4_mihyouka_Review", methods=["POST"])
def math1_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数学１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学１/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数学１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数学１/math1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/math1_4_video',methods =["post"])
def math1_4_video():
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数学１/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数学１/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学１/math1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/math1_4_mihyouka_video',methods =["post"])
def math1_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数学１/数学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数学１/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数学１/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数学１/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学１/math1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################数学２############################
################################################################################################
@app.route("/math2_")
def math2_():
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/数学２/math2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/math2_1")
def math2_1():
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数学２/math2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/math2_1_Review',methods = ["post"])
def math2_1_Review():
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学２/math2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/math2_1_mihyouka_Review", methods=["POST"])
def math2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数学２/math2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/math2_1_video',methods =["post"])
def math2_1_video():
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数学２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数学２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学２/math2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/math2_1_mihyouka_video',methods =["post"])
def math2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数学２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数学２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学２/math2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/math2_2")
def math2_2():
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数学２/math2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/math2_2_Review',methods = ["post"])
def math2_2_Review():
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学２/math2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/math2_2_mihyouka_Review", methods=["POST"])
def math2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数学２/math2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/math2_2_video',methods =["post"])
def math2_2_video():
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数学２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数学２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学２/math2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/math2_2_mihyouka_video',methods =["post"])
def math2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数学２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数学２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学２/math2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/math2_3")
def math2_3():
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数学２/math2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/math2_3_Review',methods = ["post"])
def math2_3_Review():
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学２/math2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/math2_3_mihyouka_Review", methods=["POST"])
def math2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数学２/math2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/math2_3_video',methods =["post"])
def math2_3_video():
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数学２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数学２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学２/math2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/math2_3_mihyouka_video',methods =["post"])
def math2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数学２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数学２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学２/math2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/math2_4")
def math2_4():
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数学２/math2_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/math2_4_Review',methods = ["post"])
def math2_4_Review():
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数学２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数学２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学２/math2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/math2_4_mihyouka_Review", methods=["POST"])
def math2_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数学２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数学２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数学２/math2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/math2_4_video',methods =["post"])
def math2_4_video():
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数学２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数学２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学２/math2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/math2_4_mihyouka_video',methods =["post"])
def math2_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数学２/数学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数学２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数学２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数学２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学２/math2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################数学演習（情報）############################
################################################################################################
@app.route("/math_exe")
def math_exe():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/数学演習（情報）/math_exe_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/math_exe1")
def math_exe1():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数学演習（情報）/math_exe1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/math_exe1_Review',methods = ["post"])
def math_exe1_Review():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学演習（情報）/math_exe1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/math_exe1_mihyouka_Review", methods=["POST"])
def math_exe1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数学演習（情報）/math_exe1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/math_exe1_video',methods =["post"])
def math_exe1_video():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学演習（情報）/math_exe1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/math_exe1_mihyouka_video',methods =["post"])
def math_exe1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学演習（情報）/math_exe1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/math_exe2")
def math_exe2():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数学演習（情報）/math_exe2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/math_exe2_Review',methods = ["post"])
def math_exe2_Review():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学演習（情報）/math_exe2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/math_exe2_mihyouka_Review", methods=["POST"])
def math_exe2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数学演習（情報）/math_exe2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/math_exe2_video',methods =["post"])
def math_exe2_video():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学演習（情報）/math_exe2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/math_exe2_mihyouka_video',methods =["post"])
def math_exe2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学演習（情報）/math_exe2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/math_exe3")
def math_exe3():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数学演習（情報）/math_exe3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/math_exe3_Review',methods = ["post"])
def math_exe3_Review():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学演習（情報）/math_exe3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/math_exe3_mihyouka_Review", methods=["POST"])
def math_exe3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数学演習（情報）/math_exe3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/math_exe3_video',methods =["post"])
def math_exe3_video():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学演習（情報）/math_exe3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/math_exe3_mihyouka_video',methods =["post"])
def math_exe3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学演習（情報）/math_exe3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/math_exe4")
def math_exe4():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数学演習（情報）/math_exe4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/math_exe4_Review',methods = ["post"])
def math_exe4_Review():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学演習（情報）/math_exe4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/math_exe4_mihyouka_Review", methods=["POST"])
def math_exe4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数学演習（情報）/math_exe4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/math_exe4_video',methods =["post"])
def math_exe4_video():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学演習（情報）/math_exe4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/math_exe4_mihyouka_video',methods =["post"])
def math_exe4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学演習（情報）/math_exe4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/math_exe5")
def math_exe5():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数学演習（情報）/math_exe5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/math_exe5_Review',methods = ["post"])
def math_exe5_Review():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学演習（情報）/math_exe5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/math_exe5_mihyouka_Review", methods=["POST"])
def math_exe5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数学演習（情報）/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数学演習（情報）/math_exe5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/math_exe5_video',methods =["post"])
def math_exe5_video():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学演習（情報）/math_exe5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/math_exe5_mihyouka_video',methods =["post"])
def math_exe5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数学演習（情報）/数学演習（情報）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数学演習（情報）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数学演習（情報）/math_exe5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################数値解析############################
################################################################################################
@app.route("/nume_ana")
def nume_ana():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/数値解析/nume_ana_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/nume_ana1")
def nume_ana1():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数値解析/nume_ana1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/nume_ana1_Review',methods = ["post"])
def nume_ana1_Review():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/nume_ana1_mihyouka_Review", methods=["POST"])
def nume_ana1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数値解析/nume_ana1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/nume_ana1_video',methods =["post"])
def nume_ana1_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数値解析/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/nume_ana1_mihyouka_video',methods =["post"])
def nume_ana1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数値解析/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/nume_ana2")
def nume_ana2():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数値解析/nume_ana2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/nume_ana2_Review',methods = ["post"])
def nume_ana2_Review():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/nume_ana2_mihyouka_Review", methods=["POST"])
def nume_ana2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数値解析/nume_ana2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/nume_ana2_video',methods =["post"])
def nume_ana2_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数値解析/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/nume_ana2_mihyouka_video',methods =["post"])
def nume_ana2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数値解析/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/nume_ana3")
def nume_ana3():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数値解析/nume_ana3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/nume_ana3_Review',methods = ["post"])
def nume_ana3_Review():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/nume_ana3_mihyouka_Review", methods=["POST"])
def nume_ana3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数値解析/nume_ana3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/nume_ana3_video',methods =["post"])
def nume_ana3_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数値解析/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/nume_ana3_mihyouka_video',methods =["post"])
def nume_ana3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数値解析/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/nume_ana4")
def nume_ana4():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数値解析/nume_ana4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/nume_ana4_Review',methods = ["post"])
def nume_ana4_Review():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/nume_ana4_mihyouka_Review", methods=["POST"])
def nume_ana4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数値解析/nume_ana4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/nume_ana4_video',methods =["post"])
def nume_ana4_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数値解析/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/nume_ana4_mihyouka_video',methods =["post"])
def nume_ana4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数値解析/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/nume_ana5")
def nume_ana5():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数値解析/nume_ana5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/nume_ana5_Review',methods = ["post"])
def nume_ana5_Review():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/nume_ana5_mihyouka_Review", methods=["POST"])
def nume_ana5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数値解析/nume_ana5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/nume_ana5_video',methods =["post"])
def nume_ana5_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数値解析/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/nume_ana5_mihyouka_video',methods =["post"])
def nume_ana5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数値解析/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/nume_ana6")
def nume_ana6():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数値解析/nume_ana6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/nume_ana6_Review',methods = ["post"])
def nume_ana6_Review():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/nume_ana6_mihyouka_Review", methods=["POST"])
def nume_ana6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数値解析/nume_ana6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/nume_ana6_video',methods =["post"])
def nume_ana6_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数値解析/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/nume_ana6_mihyouka_video',methods =["post"])
def nume_ana6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数値解析/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/nume_ana7")
def nume_ana7():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数値解析/nume_ana7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/nume_ana7_Review',methods = ["post"])
def nume_ana7_Review():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/nume_ana7_mihyouka_Review", methods=["POST"])
def nume_ana7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数値解析/nume_ana7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/nume_ana7_video',methods =["post"])
def nume_ana7_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数値解析/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/nume_ana7_mihyouka_video',methods =["post"])
def nume_ana7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数値解析/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/nume_ana8")
def nume_ana8():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数値解析/nume_ana8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/nume_ana8_Review',methods = ["post"])
def nume_ana8_Review():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/nume_ana8_mihyouka_Review", methods=["POST"])
def nume_ana8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数値解析/nume_ana8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/nume_ana8_video',methods =["post"])
def nume_ana8_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数値解析/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/nume_ana8_mihyouka_video',methods =["post"])
def nume_ana8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数値解析/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/nume_ana9")
def nume_ana9():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数値解析/nume_ana9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/nume_ana9_Review',methods = ["post"])
def nume_ana9_Review():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/nume_ana9_mihyouka_Review", methods=["POST"])
def nume_ana9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数値解析/nume_ana9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/nume_ana9_video',methods =["post"])
def nume_ana9_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数値解析/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/nume_ana9_mihyouka_video',methods =["post"])
def nume_ana9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数値解析/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/nume_ana10")
def nume_ana10():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数値解析/nume_ana10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/nume_ana10_Review',methods = ["post"])
def nume_ana10_Review():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/nume_ana10_mihyouka_Review", methods=["POST"])
def nume_ana10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数値解析/nume_ana10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/nume_ana10_video',methods =["post"])
def nume_ana10_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数値解析/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/nume_ana10_mihyouka_video',methods =["post"])
def nume_ana10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数値解析/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/nume_ana11")
def nume_ana11():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数値解析/nume_ana11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/nume_ana11_Review',methods = ["post"])
def nume_ana11_Review():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/nume_ana11_mihyouka_Review", methods=["POST"])
def nume_ana11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数値解析/nume_ana11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/nume_ana11_video',methods =["post"])
def nume_ana11_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数値解析/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/nume_ana11_mihyouka_video',methods =["post"])
def nume_ana11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数値解析/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/nume_ana12")
def nume_ana12():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数値解析/nume_ana12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/nume_ana12_Review',methods = ["post"])
def nume_ana12_Review():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/nume_ana12_mihyouka_Review", methods=["POST"])
def nume_ana12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数値解析/nume_ana12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/nume_ana12_video',methods =["post"])
def nume_ana12_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数値解析/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/nume_ana12_mihyouka_video',methods =["post"])
def nume_ana12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数値解析/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/nume_ana13")
def nume_ana13():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数値解析/nume_ana13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/nume_ana13_Review',methods = ["post"])
def nume_ana13_Review():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/nume_ana13_mihyouka_Review", methods=["POST"])
def nume_ana13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数値解析/nume_ana13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/nume_ana13_video',methods =["post"])
def nume_ana13_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数値解析/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/nume_ana13_mihyouka_video',methods =["post"])
def nume_ana13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数値解析/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/nume_ana14")
def nume_ana14():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数値解析/nume_ana14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/nume_ana14_Review',methods = ["post"])
def nume_ana14_Review():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/nume_ana14_mihyouka_Review", methods=["POST"])
def nume_ana14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数値解析/nume_ana14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/nume_ana14_video',methods =["post"])
def nume_ana14_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数値解析/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/nume_ana14_mihyouka_video',methods =["post"])
def nume_ana14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数値解析/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/nume_ana15")
def nume_ana15():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/数値解析/nume_ana15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/nume_ana15_Review',methods = ["post"])
def nume_ana15_Review():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/nume_ana15_mihyouka_Review", methods=["POST"])
def nume_ana15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/数値解析/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/数値解析/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/数値解析/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/数値解析/nume_ana15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/nume_ana15_video',methods =["post"])
def nume_ana15_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/数値解析/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/nume_ana15_mihyouka_video',methods =["post"])
def nume_ana15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/数値解析/数値解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/数値解析/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/数値解析/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/数値解析/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/数値解析/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/数値解析/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/数値解析/nume_ana15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################生体情報工学############################
################################################################################################
@app.route("/bioinfo")
def bioinfo():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/生体情報工学/bioinfo_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/bioinfo1")
def bioinfo1():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生体情報工学/bioinfo1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/bioinfo1_Review',methods = ["post"])
def bioinfo1_Review():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生体情報工学/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/bioinfo1_mihyouka_Review", methods=["POST"])
def bioinfo1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生体情報工学/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生体情報工学/bioinfo1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/bioinfo1_video',methods =["post"])
def bioinfo1_video():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生体情報工学/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/bioinfo1_mihyouka_video',methods =["post"])
def bioinfo1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生体情報工学/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/bioinfo2")
def bioinfo2():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生体情報工学/bioinfo2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/bioinfo2_Review',methods = ["post"])
def bioinfo2_Review():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生体情報工学/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/bioinfo2_mihyouka_Review", methods=["POST"])
def bioinfo2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生体情報工学/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生体情報工学/bioinfo2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/bioinfo2_video',methods =["post"])
def bioinfo2_video():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生体情報工学/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/bioinfo2_mihyouka_video',methods =["post"])
def bioinfo2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生体情報工学/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/bioinfo3")
def bioinfo3():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生体情報工学/bioinfo3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/bioinfo3_Review',methods = ["post"])
def bioinfo3_Review():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生体情報工学/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/bioinfo3_mihyouka_Review", methods=["POST"])
def bioinfo3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生体情報工学/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生体情報工学/bioinfo3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/bioinfo3_video',methods =["post"])
def bioinfo3_video():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生体情報工学/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/bioinfo3_mihyouka_video',methods =["post"])
def bioinfo3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生体情報工学/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/bioinfo4")
def bioinfo4():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生体情報工学/bioinfo4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/bioinfo4_Review',methods = ["post"])
def bioinfo4_Review():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生体情報工学/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/bioinfo4_mihyouka_Review", methods=["POST"])
def bioinfo4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生体情報工学/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生体情報工学/bioinfo4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/bioinfo4_video',methods =["post"])
def bioinfo4_video():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生体情報工学/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/bioinfo4_mihyouka_video',methods =["post"])
def bioinfo4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生体情報工学/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/bioinfo5")
def bioinfo5():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生体情報工学/bioinfo5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/bioinfo5_Review',methods = ["post"])
def bioinfo5_Review():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生体情報工学/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/bioinfo5_mihyouka_Review", methods=["POST"])
def bioinfo5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生体情報工学/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生体情報工学/bioinfo5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/bioinfo5_video',methods =["post"])
def bioinfo5_video():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生体情報工学/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/bioinfo5_mihyouka_video',methods =["post"])
def bioinfo5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生体情報工学/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/bioinfo6")
def bioinfo6():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生体情報工学/bioinfo6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/bioinfo6_Review',methods = ["post"])
def bioinfo6_Review():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生体情報工学/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/bioinfo6_mihyouka_Review", methods=["POST"])
def bioinfo6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生体情報工学/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生体情報工学/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生体情報工学/bioinfo6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/bioinfo6_video',methods =["post"])
def bioinfo6_video():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生体情報工学/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/bioinfo6_mihyouka_video',methods =["post"])
def bioinfo6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生体情報工学/生体情報工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生体情報工学/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生体情報工学/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生体情報工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生体情報工学/bioinfo6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################生物学############################
################################################################################################
@app.route("/biology")
def biology():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/生物学/biology_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/biology1")
def biology1():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生物学/biology1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/biology1_Review',methods = ["post"])
def biology1_Review():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生物学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/biology1_mihyouka_Review", methods=["POST"])
def biology1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生物学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生物学/biology1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/biology1_video',methods =["post"])
def biology1_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生物学/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/biology1_mihyouka_video',methods =["post"])
def biology1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生物学/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/biology2")
def biology2():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生物学/biology2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/biology2_Review',methods = ["post"])
def biology2_Review():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生物学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/biology2_mihyouka_Review", methods=["POST"])
def biology2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生物学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生物学/biology2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/biology2_video',methods =["post"])
def biology2_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生物学/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/biology2_mihyouka_video',methods =["post"])
def biology2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生物学/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/biology3")
def biology3():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生物学/biology3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/biology3_Review',methods = ["post"])
def biology3_Review():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生物学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/biology3_mihyouka_Review", methods=["POST"])
def biology3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生物学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生物学/biology3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/biology3_video',methods =["post"])
def biology3_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生物学/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/biology3_mihyouka_video',methods =["post"])
def biology3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生物学/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/biology4")
def biology4():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生物学/biology4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/biology4_Review',methods = ["post"])
def biology4_Review():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生物学/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/biology4_mihyouka_Review", methods=["POST"])
def biology4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生物学/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生物学/biology4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/biology4_video',methods =["post"])
def biology4_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生物学/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/biology4_mihyouka_video',methods =["post"])
def biology4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生物学/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/biology5")
def biology5():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生物学/biology5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/biology5_Review',methods = ["post"])
def biology5_Review():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生物学/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/biology5_mihyouka_Review", methods=["POST"])
def biology5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生物学/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生物学/biology5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/biology5_video',methods =["post"])
def biology5_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生物学/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/biology5_mihyouka_video',methods =["post"])
def biology5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生物学/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/biology6")
def biology6():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生物学/biology6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/biology6_Review',methods = ["post"])
def biology6_Review():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生物学/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/biology6_mihyouka_Review", methods=["POST"])
def biology6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生物学/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生物学/biology6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/biology6_video',methods =["post"])
def biology6_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生物学/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/biology6_mihyouka_video',methods =["post"])
def biology6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生物学/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/biology7")
def biology7():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生物学/biology7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/biology7_Review',methods = ["post"])
def biology7_Review():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生物学/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/biology7_mihyouka_Review", methods=["POST"])
def biology7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生物学/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生物学/biology7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/biology7_video',methods =["post"])
def biology7_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生物学/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/biology7_mihyouka_video',methods =["post"])
def biology7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生物学/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/biology8")
def biology8():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生物学/biology8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/biology8_Review',methods = ["post"])
def biology8_Review():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生物学/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/biology8_mihyouka_Review", methods=["POST"])
def biology8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生物学/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生物学/biology8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/biology8_video',methods =["post"])
def biology8_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生物学/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/biology8_mihyouka_video',methods =["post"])
def biology8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生物学/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/biology9")
def biology9():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生物学/biology9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/biology9_Review',methods = ["post"])
def biology9_Review():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生物学/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/biology9_mihyouka_Review", methods=["POST"])
def biology9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生物学/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生物学/biology9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/biology9_video',methods =["post"])
def biology9_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生物学/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/biology9_mihyouka_video',methods =["post"])
def biology9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生物学/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/biology10")
def biology10():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生物学/biology10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/biology10_Review',methods = ["post"])
def biology10_Review():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生物学/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/biology10_mihyouka_Review", methods=["POST"])
def biology10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生物学/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生物学/biology10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/biology10_video',methods =["post"])
def biology10_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生物学/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/biology10_mihyouka_video',methods =["post"])
def biology10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生物学/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/biology11")
def biology11():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生物学/biology11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/biology11_Review',methods = ["post"])
def biology11_Review():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生物学/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/biology11_mihyouka_Review", methods=["POST"])
def biology11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生物学/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生物学/biology11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/biology11_video',methods =["post"])
def biology11_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生物学/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/biology11_mihyouka_video',methods =["post"])
def biology11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生物学/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/biology12")
def biology12():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生物学/biology12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/biology12_Review',methods = ["post"])
def biology12_Review():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生物学/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/biology12_mihyouka_Review", methods=["POST"])
def biology12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生物学/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生物学/biology12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/biology12_video',methods =["post"])
def biology12_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生物学/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/biology12_mihyouka_video',methods =["post"])
def biology12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生物学/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/biology13")
def biology13():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生物学/biology13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/biology13_Review',methods = ["post"])
def biology13_Review():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生物学/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/biology13_mihyouka_Review", methods=["POST"])
def biology13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生物学/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生物学/biology13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/biology13_video',methods =["post"])
def biology13_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生物学/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/biology13_mihyouka_video',methods =["post"])
def biology13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生物学/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/biology14")
def biology14():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生物学/biology14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/biology14_Review',methods = ["post"])
def biology14_Review():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生物学/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/biology14_mihyouka_Review", methods=["POST"])
def biology14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生物学/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生物学/biology14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/biology14_video',methods =["post"])
def biology14_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生物学/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/biology14_mihyouka_video',methods =["post"])
def biology14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生物学/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/biology15")
def biology15():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/生物学/biology15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/biology15_Review',methods = ["post"])
def biology15_Review():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/生物学/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/biology15_mihyouka_Review", methods=["POST"])
def biology15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/生物学/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/生物学/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/生物学/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/生物学/biology15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/biology15_video',methods =["post"])
def biology15_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/生物学/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/biology15_mihyouka_video',methods =["post"])
def biology15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/生物学/生物学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/生物学/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/生物学/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/生物学/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/生物学/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/生物学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/生物学/biology15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################専門ゼミ############################
################################################################################################
@app.route("/spe_semi")
def spe_semi():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/専門ゼミ/spe_semi_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/spe_semi1")
def spe_semi1():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/専門ゼミ/spe_semi1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_semi1_Review',methods = ["post"])
def spe_semi1_Review():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_semi1_mihyouka_Review", methods=["POST"])
def spe_semi1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/専門ゼミ/spe_semi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_semi1_video',methods =["post"])
def spe_semi1_video():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_semi1_mihyouka_video',methods =["post"])
def spe_semi1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/spe_semi2")
def spe_semi2():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/専門ゼミ/spe_semi2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_semi2_Review',methods = ["post"])
def spe_semi2_Review():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_semi2_mihyouka_Review", methods=["POST"])
def spe_semi2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/専門ゼミ/spe_semi2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_semi2_video',methods =["post"])
def spe_semi2_video():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_semi2_mihyouka_video',methods =["post"])
def spe_semi2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/spe_semi3")
def spe_semi3():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/専門ゼミ/spe_semi3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_semi3_Review',methods = ["post"])
def spe_semi3_Review():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_semi3_mihyouka_Review", methods=["POST"])
def spe_semi3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/専門ゼミ/spe_semi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_semi3_video',methods =["post"])
def spe_semi3_video():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_semi3_mihyouka_video',methods =["post"])
def spe_semi3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/spe_semi4")
def spe_semi4():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/専門ゼミ/spe_semi4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_semi4_Review',methods = ["post"])
def spe_semi4_Review():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_semi4_mihyouka_Review", methods=["POST"])
def spe_semi4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/専門ゼミ/spe_semi4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_semi4_video',methods =["post"])
def spe_semi4_video():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_semi4_mihyouka_video',methods =["post"])
def spe_semi4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/spe_semi5")
def spe_semi5():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/専門ゼミ/spe_semi5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_semi5_Review',methods = ["post"])
def spe_semi5_Review():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_semi5_mihyouka_Review", methods=["POST"])
def spe_semi5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/専門ゼミ/spe_semi5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_semi5_video',methods =["post"])
def spe_semi5_video():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_semi5_mihyouka_video',methods =["post"])
def spe_semi5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/spe_semi6")
def spe_semi6():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/専門ゼミ/spe_semi6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_semi6_Review',methods = ["post"])
def spe_semi6_Review():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_semi6_mihyouka_Review", methods=["POST"])
def spe_semi6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/専門ゼミ/spe_semi6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_semi6_video',methods =["post"])
def spe_semi6_video():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_semi6_mihyouka_video',methods =["post"])
def spe_semi6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/spe_semi7")
def spe_semi7():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/専門ゼミ/spe_semi7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/spe_semi7_Review',methods = ["post"])
def spe_semi7_Review():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/spe_semi7_mihyouka_Review", methods=["POST"])
def spe_semi7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/専門ゼミ/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/専門ゼミ/spe_semi7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/spe_semi7_video',methods =["post"])
def spe_semi7_video():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/spe_semi7_mihyouka_video',methods =["post"])
def spe_semi7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/専門ゼミ/専門ゼミ.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/専門ゼミ/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/専門ゼミ/spe_semi7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################線形代数１############################
################################################################################################
@app.route("/line_algebra1_")
def line_algebra1_():
    df_key = pd.read_csv("Kamoku/線形代数１/線形代数１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/線形代数１/line_algebra1__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/line_algebra1_1")
def line_algebra1_1():
    df_key = pd.read_csv("Kamoku/線形代数１/線形代数１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/線形代数１/line_algebra1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/line_algebra1_1_Review',methods = ["post"])
def line_algebra1_1_Review():
    df_key = pd.read_csv("Kamoku/線形代数１/線形代数１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/線形代数１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/線形代数１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数１/line_algebra1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/line_algebra1_1_mihyouka_Review", methods=["POST"])
def line_algebra1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/線形代数１/線形代数１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/線形代数１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/線形代数１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/線形代数１/line_algebra1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/line_algebra1_1_video',methods =["post"])
def line_algebra1_1_video():
    df_key = pd.read_csv("Kamoku/線形代数１/線形代数１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/線形代数１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/線形代数１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数１/line_algebra1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/line_algebra1_1_mihyouka_video',methods =["post"])
def line_algebra1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/線形代数１/線形代数１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/線形代数１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/線形代数１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数１/line_algebra1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/line_algebra1_2")
def line_algebra1_2():
    df_key = pd.read_csv("Kamoku/線形代数１/線形代数１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/線形代数１/line_algebra1_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/line_algebra1_2_Review',methods = ["post"])
def line_algebra1_2_Review():
    df_key = pd.read_csv("Kamoku/線形代数１/線形代数１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/線形代数１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数１/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/線形代数１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数１/line_algebra1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/line_algebra1_2_mihyouka_Review", methods=["POST"])
def line_algebra1_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/線形代数１/線形代数１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/線形代数１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数１/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/線形代数１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/線形代数１/line_algebra1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/line_algebra1_2_video',methods =["post"])
def line_algebra1_2_video():
    df_key = pd.read_csv("Kamoku/線形代数１/線形代数１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/線形代数１/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/線形代数１/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数１/line_algebra1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/line_algebra1_2_mihyouka_video',methods =["post"])
def line_algebra1_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/線形代数１/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/線形代数１/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数１/line_algebra1_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/line_algebra1_3")
def line_algebra1_3():
    df_key = pd.read_csv("Kamoku/線形代数１/線形代数１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/線形代数１/line_algebra1_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/line_algebra1_3_Review',methods = ["post"])
def line_algebra1_3_Review():
    df_key = pd.read_csv("Kamoku/線形代数１/線形代数１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/線形代数１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数１/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/線形代数１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数１/line_algebra1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/line_algebra1_3_mihyouka_Review", methods=["POST"])
def line_algebra1_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/線形代数１/線形代数１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/線形代数１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数１/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/線形代数１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/線形代数１/line_algebra1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/line_algebra1_3_video',methods =["post"])
def line_algebra1_3_video():
    df_key = pd.read_csv("Kamoku/線形代数１/線形代数１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/線形代数１/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/線形代数１/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数１/line_algebra1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/line_algebra1_3_mihyouka_video',methods =["post"])
def line_algebra1_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/線形代数１/線形代数１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/線形代数１/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/線形代数１/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/線形代数１/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数１/line_algebra1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################線形代数２############################
################################################################################################
@app.route("/line_algebra2_")
def line_algebra2_():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/線形代数２/line_algebra2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/line_algebra2_1")
def line_algebra2_1():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/線形代数２/line_algebra2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/line_algebra2_1_Review',methods = ["post"])
def line_algebra2_1_Review():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/line_algebra2_1_mihyouka_Review", methods=["POST"])
def line_algebra2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/線形代数２/line_algebra2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/line_algebra2_1_video',methods =["post"])
def line_algebra2_1_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/線形代数２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/line_algebra2_1_mihyouka_video',methods =["post"])
def line_algebra2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/線形代数２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/line_algebra2_2")
def line_algebra2_2():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/線形代数２/line_algebra2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/line_algebra2_2_Review',methods = ["post"])
def line_algebra2_2_Review():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/line_algebra2_2_mihyouka_Review", methods=["POST"])
def line_algebra2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/線形代数２/line_algebra2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/line_algebra2_2_video',methods =["post"])
def line_algebra2_2_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/線形代数２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/line_algebra2_2_mihyouka_video',methods =["post"])
def line_algebra2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/線形代数２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/line_algebra2_3")
def line_algebra2_3():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/線形代数２/line_algebra2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/line_algebra2_3_Review',methods = ["post"])
def line_algebra2_3_Review():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/line_algebra2_3_mihyouka_Review", methods=["POST"])
def line_algebra2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/線形代数２/line_algebra2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/line_algebra2_3_video',methods =["post"])
def line_algebra2_3_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/線形代数２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/line_algebra2_3_mihyouka_video',methods =["post"])
def line_algebra2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/線形代数２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/line_algebra2_4")
def line_algebra2_4():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/線形代数２/line_algebra2_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/line_algebra2_4_Review',methods = ["post"])
def line_algebra2_4_Review():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/line_algebra2_4_mihyouka_Review", methods=["POST"])
def line_algebra2_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/線形代数２/line_algebra2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/line_algebra2_4_video',methods =["post"])
def line_algebra2_4_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/線形代数２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/line_algebra2_4_mihyouka_video',methods =["post"])
def line_algebra2_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/線形代数２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/line_algebra2_5")
def line_algebra2_5():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/線形代数２/line_algebra2_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/line_algebra2_5_Review',methods = ["post"])
def line_algebra2_5_Review():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/line_algebra2_5_mihyouka_Review", methods=["POST"])
def line_algebra2_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/線形代数２/line_algebra2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/line_algebra2_5_video',methods =["post"])
def line_algebra2_5_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/線形代数２/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/line_algebra2_5_mihyouka_video',methods =["post"])
def line_algebra2_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/線形代数２/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/line_algebra2_6")
def line_algebra2_6():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/線形代数２/line_algebra2_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/line_algebra2_6_Review',methods = ["post"])
def line_algebra2_6_Review():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/line_algebra2_6_mihyouka_Review", methods=["POST"])
def line_algebra2_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/線形代数２/line_algebra2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/line_algebra2_6_video',methods =["post"])
def line_algebra2_6_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/線形代数２/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/line_algebra2_6_mihyouka_video',methods =["post"])
def line_algebra2_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/線形代数２/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/line_algebra2_7")
def line_algebra2_7():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/線形代数２/line_algebra2_7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/line_algebra2_7_Review',methods = ["post"])
def line_algebra2_7_Review():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/line_algebra2_7_mihyouka_Review", methods=["POST"])
def line_algebra2_7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/線形代数２/line_algebra2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/line_algebra2_7_video',methods =["post"])
def line_algebra2_7_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/線形代数２/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/line_algebra2_7_mihyouka_video',methods =["post"])
def line_algebra2_7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/線形代数２/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/line_algebra2_8")
def line_algebra2_8():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/線形代数２/line_algebra2_8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/line_algebra2_8_Review',methods = ["post"])
def line_algebra2_8_Review():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/line_algebra2_8_mihyouka_Review", methods=["POST"])
def line_algebra2_8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/線形代数２/line_algebra2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/line_algebra2_8_video',methods =["post"])
def line_algebra2_8_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/線形代数２/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/line_algebra2_8_mihyouka_video',methods =["post"])
def line_algebra2_8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/線形代数２/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/line_algebra2_9")
def line_algebra2_9():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/線形代数２/line_algebra2_9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/line_algebra2_9_Review',methods = ["post"])
def line_algebra2_9_Review():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/line_algebra2_9_mihyouka_Review", methods=["POST"])
def line_algebra2_9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/線形代数２/line_algebra2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/line_algebra2_9_video',methods =["post"])
def line_algebra2_9_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/線形代数２/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/line_algebra2_9_mihyouka_video',methods =["post"])
def line_algebra2_9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/線形代数２/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/line_algebra2_10")
def line_algebra2_10():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/線形代数２/line_algebra2_10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/line_algebra2_10_Review',methods = ["post"])
def line_algebra2_10_Review():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/line_algebra2_10_mihyouka_Review", methods=["POST"])
def line_algebra2_10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/線形代数２/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/線形代数２/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/線形代数２/line_algebra2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/line_algebra2_10_video',methods =["post"])
def line_algebra2_10_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/線形代数２/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/line_algebra2_10_mihyouka_video',methods =["post"])
def line_algebra2_10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/線形代数２/線形代数２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/線形代数２/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/線形代数２/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/線形代数２/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/線形代数２/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/線形代数２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/線形代数２/line_algebra2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################組み込みシステム工学############################
################################################################################################
@app.route("/embed_syst_engi")
def embed_syst_engi():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/組み込みシステム工学/embed_syst_engi_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/embed_syst_engi1")
def embed_syst_engi1():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/組み込みシステム工学/embed_syst_engi1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/embed_syst_engi1_Review',methods = ["post"])
def embed_syst_engi1_Review():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/embed_syst_engi1_mihyouka_Review", methods=["POST"])
def embed_syst_engi1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/組み込みシステム工学/embed_syst_engi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/embed_syst_engi1_video',methods =["post"])
def embed_syst_engi1_video():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/embed_syst_engi1_mihyouka_video',methods =["post"])
def embed_syst_engi1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/embed_syst_engi2")
def embed_syst_engi2():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/組み込みシステム工学/embed_syst_engi2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/embed_syst_engi2_Review',methods = ["post"])
def embed_syst_engi2_Review():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/embed_syst_engi2_mihyouka_Review", methods=["POST"])
def embed_syst_engi2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/組み込みシステム工学/embed_syst_engi2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/embed_syst_engi2_video',methods =["post"])
def embed_syst_engi2_video():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/embed_syst_engi2_mihyouka_video',methods =["post"])
def embed_syst_engi2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/embed_syst_engi3")
def embed_syst_engi3():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/組み込みシステム工学/embed_syst_engi3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/embed_syst_engi3_Review',methods = ["post"])
def embed_syst_engi3_Review():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/embed_syst_engi3_mihyouka_Review", methods=["POST"])
def embed_syst_engi3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/組み込みシステム工学/embed_syst_engi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/embed_syst_engi3_video',methods =["post"])
def embed_syst_engi3_video():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/embed_syst_engi3_mihyouka_video',methods =["post"])
def embed_syst_engi3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/embed_syst_engi4")
def embed_syst_engi4():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/組み込みシステム工学/embed_syst_engi4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/embed_syst_engi4_Review',methods = ["post"])
def embed_syst_engi4_Review():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/embed_syst_engi4_mihyouka_Review", methods=["POST"])
def embed_syst_engi4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/組み込みシステム工学/embed_syst_engi4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/embed_syst_engi4_video',methods =["post"])
def embed_syst_engi4_video():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/embed_syst_engi4_mihyouka_video',methods =["post"])
def embed_syst_engi4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/embed_syst_engi5")
def embed_syst_engi5():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/組み込みシステム工学/embed_syst_engi5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/embed_syst_engi5_Review',methods = ["post"])
def embed_syst_engi5_Review():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/embed_syst_engi5_mihyouka_Review", methods=["POST"])
def embed_syst_engi5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/組み込みシステム工学/embed_syst_engi5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/embed_syst_engi5_video',methods =["post"])
def embed_syst_engi5_video():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/embed_syst_engi5_mihyouka_video',methods =["post"])
def embed_syst_engi5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/embed_syst_engi6")
def embed_syst_engi6():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/組み込みシステム工学/embed_syst_engi6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/embed_syst_engi6_Review',methods = ["post"])
def embed_syst_engi6_Review():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/embed_syst_engi6_mihyouka_Review", methods=["POST"])
def embed_syst_engi6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/組み込みシステム工学/embed_syst_engi6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/embed_syst_engi6_video',methods =["post"])
def embed_syst_engi6_video():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/embed_syst_engi6_mihyouka_video',methods =["post"])
def embed_syst_engi6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/組み込みシステム工学/組み込みシステム工学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/組み込みシステム工学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/組み込みシステム工学/embed_syst_engi6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################総合英語１############################
################################################################################################
@app.route("/compre_eng1_")
def compre_eng1_():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/総合英語１/compre_eng1__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/compre_eng1_1")
def compre_eng1_1():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語１/compre_eng1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng1_1_Review',methods = ["post"])
def compre_eng1_1_Review():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng1_1_mihyouka_Review", methods=["POST"])
def compre_eng1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語１/compre_eng1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng1_1_video',methods =["post"])
def compre_eng1_1_video():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng1_1_mihyouka_video',methods =["post"])
def compre_eng1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/compre_eng1_2")
def compre_eng1_2():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語１/compre_eng1_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng1_2_Review',methods = ["post"])
def compre_eng1_2_Review():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語１/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng1_2_mihyouka_Review", methods=["POST"])
def compre_eng1_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語１/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語１/compre_eng1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng1_2_video',methods =["post"])
def compre_eng1_2_video():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語１/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語１/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng1_2_mihyouka_video',methods =["post"])
def compre_eng1_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語１/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語１/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/compre_eng1_3")
def compre_eng1_3():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語１/compre_eng1_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng1_3_Review',methods = ["post"])
def compre_eng1_3_Review():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語１/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng1_3_mihyouka_Review", methods=["POST"])
def compre_eng1_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語１/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語１/compre_eng1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng1_3_video',methods =["post"])
def compre_eng1_3_video():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語１/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語１/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng1_3_mihyouka_video',methods =["post"])
def compre_eng1_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語１/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語１/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/compre_eng1_4")
def compre_eng1_4():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語１/compre_eng1_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng1_4_Review',methods = ["post"])
def compre_eng1_4_Review():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語１/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng1_4_mihyouka_Review", methods=["POST"])
def compre_eng1_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語１/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語１/compre_eng1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng1_4_video',methods =["post"])
def compre_eng1_4_video():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語１/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語１/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng1_4_mihyouka_video',methods =["post"])
def compre_eng1_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語１/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語１/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/compre_eng1_5")
def compre_eng1_5():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語１/compre_eng1_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng1_5_Review',methods = ["post"])
def compre_eng1_5_Review():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語１/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng1_5_mihyouka_Review", methods=["POST"])
def compre_eng1_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語１/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語１/compre_eng1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng1_5_video',methods =["post"])
def compre_eng1_5_video():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語１/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語１/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng1_5_mihyouka_video',methods =["post"])
def compre_eng1_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語１/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語１/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/compre_eng1_6")
def compre_eng1_6():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語１/compre_eng1_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng1_6_Review',methods = ["post"])
def compre_eng1_6_Review():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語１/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng1_6_mihyouka_Review", methods=["POST"])
def compre_eng1_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語１/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語１/compre_eng1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng1_6_video',methods =["post"])
def compre_eng1_6_video():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語１/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語１/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語１/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng1_6_mihyouka_video',methods =["post"])
def compre_eng1_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語１/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語１/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語１/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/compre_eng1_7")
def compre_eng1_7():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語１/compre_eng1_7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng1_7_Review',methods = ["post"])
def compre_eng1_7_Review():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語１/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng1_7_mihyouka_Review", methods=["POST"])
def compre_eng1_7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語１/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語１/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語１/compre_eng1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng1_7_video',methods =["post"])
def compre_eng1_7_video():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語１/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語１/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語１/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng1_7_mihyouka_video',methods =["post"])
def compre_eng1_7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語１/総合英語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語１/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語１/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語１/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語１/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語１/compre_eng1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################総合英語２###########################
################################################################################################
@app.route("/compre_eng2_")
def compre_eng2_():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/総合英語２/compre_eng2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/compre_eng2_1")
def compre_eng2_1():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語２/compre_eng2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng2_1_Review',methods = ["post"])
def compre_eng2_1_Review():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語２/compre_eng2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng2_1_mihyouka_Review", methods=["POST"])
def compre_eng2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語２/compre_eng2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng2_1_video',methods =["post"])
def compre_eng2_1_video():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語２/compre_eng2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng2_1_mihyouka_video',methods =["post"])
def compre_eng2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語２/compre_eng2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/compre_eng2_2")
def compre_eng2_2():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語２/compre_eng2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng2_2_Review',methods = ["post"])
def compre_eng2_2_Review():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語２/compre_eng2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng2_2_mihyouka_Review", methods=["POST"])
def compre_eng2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語２/compre_eng2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng2_2_video',methods =["post"])
def compre_eng2_2_video():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語２/compre_eng2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng2_2_mihyouka_video',methods =["post"])
def compre_eng2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語２/compre_eng2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/compre_eng2_3")
def compre_eng2_3():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語２/compre_eng2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng2_3_Review',methods = ["post"])
def compre_eng2_3_Review():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語２/compre_eng2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng2_3_mihyouka_Review", methods=["POST"])
def compre_eng2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語２/compre_eng2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng2_3_video',methods =["post"])
def compre_eng2_3_video():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語２/compre_eng2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng2_3_mihyouka_video',methods =["post"])
def compre_eng2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語２/compre_eng2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/compre_eng2_4")
def compre_eng2_4():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語２/compre_eng2_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng2_4_Review',methods = ["post"])
def compre_eng2_4_Review():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語２/compre_eng2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng2_4_mihyouka_Review", methods=["POST"])
def compre_eng2_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語２/compre_eng2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng2_4_video',methods =["post"])
def compre_eng2_4_video():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語２/compre_eng2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng2_4_mihyouka_video',methods =["post"])
def compre_eng2_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語２/compre_eng2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/compre_eng2_5")
def compre_eng2_5():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語２/compre_eng2_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng2_5_Review',methods = ["post"])
def compre_eng2_5_Review():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語２/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語２/compre_eng2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng2_5_mihyouka_Review", methods=["POST"])
def compre_eng2_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語２/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語２/compre_eng2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng2_5_video',methods =["post"])
def compre_eng2_5_video():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語２/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語２/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語２/compre_eng2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng2_5_mihyouka_video',methods =["post"])
def compre_eng2_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語２/総合英語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語２/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語２/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語２/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語２/compre_eng2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################総合英語３############################
################################################################################################
@app.route("/compre_eng3_")
def compre_eng3_():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/総合英語３/compre_eng3__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/compre_eng3_1")
def compre_eng3_1():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語３/compre_eng3_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng3_1_Review',methods = ["post"])
def compre_eng3_1_Review():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語３/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng3_1_mihyouka_Review", methods=["POST"])
def compre_eng3_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語３/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語３/compre_eng3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng3_1_video',methods =["post"])
def compre_eng3_1_video():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語３/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語３/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語３/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng3_1_mihyouka_video',methods =["post"])
def compre_eng3_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語３/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語３/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語３/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/compre_eng3_2")
def compre_eng3_2():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語３/compre_eng3_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng3_2_Review',methods = ["post"])
def compre_eng3_2_Review():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語３/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng3_2_mihyouka_Review", methods=["POST"])
def compre_eng3_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語３/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語３/compre_eng3_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng3_2_video',methods =["post"])
def compre_eng3_2_video():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語３/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語３/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語３/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng3_2_mihyouka_video',methods =["post"])
def compre_eng3_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語３/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語３/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語３/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/compre_eng3_3")
def compre_eng3_3():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語３/compre_eng3_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng3_3_Review',methods = ["post"])
def compre_eng3_3_Review():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語３/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng3_3_mihyouka_Review", methods=["POST"])
def compre_eng3_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語３/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語３/compre_eng3_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng3_3_video',methods =["post"])
def compre_eng3_3_video():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語３/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語３/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語３/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng3_3_mihyouka_video',methods =["post"])
def compre_eng3_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語３/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語３/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語３/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/compre_eng3_4")
def compre_eng3_4():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語３/compre_eng3_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng3_4_Review',methods = ["post"])
def compre_eng3_4_Review():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語３/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng3_4_mihyouka_Review", methods=["POST"])
def compre_eng3_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語３/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語３/compre_eng3_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng3_4_video',methods =["post"])
def compre_eng3_4_video():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語３/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語３/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語３/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng3_4_mihyouka_video',methods =["post"])
def compre_eng3_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語３/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語３/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語３/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/compre_eng3_5")
def compre_eng3_5():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語３/compre_eng3_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng3_5_Review',methods = ["post"])
def compre_eng3_5_Review():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語３/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng3_5_mihyouka_Review", methods=["POST"])
def compre_eng3_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語３/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語３/compre_eng3_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng3_5_video',methods =["post"])
def compre_eng3_5_video():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語３/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語３/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語３/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng3_5_mihyouka_video',methods =["post"])
def compre_eng3_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語３/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語３/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語３/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/compre_eng3_6")
def compre_eng3_6():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語３/compre_eng3_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng3_6_Review',methods = ["post"])
def compre_eng3_6_Review():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語３/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng3_6_mihyouka_Review", methods=["POST"])
def compre_eng3_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語３/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語３/compre_eng3_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng3_6_video',methods =["post"])
def compre_eng3_6_video():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語３/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語３/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語３/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng3_6_mihyouka_video',methods =["post"])
def compre_eng3_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語３/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語３/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語３/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/compre_eng3_7")
def compre_eng3_7():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語３/compre_eng3_7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng3_7_Review',methods = ["post"])
def compre_eng3_7_Review():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語３/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng3_7_mihyouka_Review", methods=["POST"])
def compre_eng3_7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語３/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語３/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語３/compre_eng3_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng3_7_video',methods =["post"])
def compre_eng3_7_video():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語３/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語３/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語３/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng3_7_mihyouka_video',methods =["post"])
def compre_eng3_7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語３/総合英語３.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語３/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語３/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語３/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語３/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語３/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語３/compre_eng3_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################総合英語４############################
################################################################################################
@app.route("/compre_eng4_")
def compre_eng4_():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/総合英語４/compre_eng4__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/compre_eng4_1")
def compre_eng4_1():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語４/compre_eng4_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng4_1_Review',methods = ["post"])
def compre_eng4_1_Review():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語４/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語４/compre_eng4_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng4_1_mihyouka_Review", methods=["POST"])
def compre_eng4_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語４/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語４/compre_eng4_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng4_1_video',methods =["post"])
def compre_eng4_1_video():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語４/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語４/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語４/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語４/compre_eng4_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng4_1_mihyouka_video',methods =["post"])
def compre_eng4_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語４/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語４/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語４/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語４/compre_eng4_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/compre_eng4_2")
def compre_eng4_2():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語４/compre_eng4_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng4_2_Review',methods = ["post"])
def compre_eng4_2_Review():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語４/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語４/compre_eng4_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng4_2_mihyouka_Review", methods=["POST"])
def compre_eng4_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語４/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語４/compre_eng4_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng4_2_video',methods =["post"])
def compre_eng4_2_video():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語４/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語４/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語４/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語４/compre_eng4_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng4_2_mihyouka_video',methods =["post"])
def compre_eng4_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語４/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語４/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語４/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語４/compre_eng4_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/compre_eng4_3")
def compre_eng4_3():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語４/compre_eng4_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng4_3_Review',methods = ["post"])
def compre_eng4_3_Review():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語４/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語４/compre_eng4_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng4_3_mihyouka_Review", methods=["POST"])
def compre_eng4_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語４/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語４/compre_eng4_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng4_3_video',methods =["post"])
def compre_eng4_3_video():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語４/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語４/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語４/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語４/compre_eng4_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng4_3_mihyouka_video',methods =["post"])
def compre_eng4_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語４/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語４/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語４/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語４/compre_eng4_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/compre_eng4_4")
def compre_eng4_4():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語４/compre_eng4_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng4_4_Review',methods = ["post"])
def compre_eng4_4_Review():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語４/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語４/compre_eng4_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng4_4_mihyouka_Review", methods=["POST"])
def compre_eng4_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語４/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語４/compre_eng4_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng4_4_video',methods =["post"])
def compre_eng4_4_video():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語４/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語４/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語４/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語４/compre_eng4_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng4_4_mihyouka_video',methods =["post"])
def compre_eng4_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語４/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語４/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語４/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語４/compre_eng4_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/compre_eng4_5")
def compre_eng4_5():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/総合英語４/compre_eng4_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compre_eng4_5_Review',methods = ["post"])
def compre_eng4_5_Review():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語４/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語４/compre_eng4_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compre_eng4_5_mihyouka_Review", methods=["POST"])
def compre_eng4_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/総合英語４/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/総合英語４/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/総合英語４/compre_eng4_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compre_eng4_5_video',methods =["post"])
def compre_eng4_5_video():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/総合英語４/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/総合英語４/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語４/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語４/compre_eng4_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compre_eng4_5_mihyouka_video',methods =["post"])
def compre_eng4_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/総合英語４/総合英語４.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/総合英語４/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/総合英語４/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/総合英語４/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/総合英語４/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/総合英語４/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/総合英語４/compre_eng4_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################卒業研究１############################
################################################################################################
@app.route("/grad_rese1_")
def grad_rese1_():
    df_key = pd.read_csv("Kamoku/卒業研究１/卒業研究１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/卒業研究１/grad_rese1__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/grad_rese1_1")
def grad_rese1_1():
    df_key = pd.read_csv("Kamoku/卒業研究１/卒業研究１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/卒業研究１/grad_rese1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/grad_rese1_1_Review',methods = ["post"])
def grad_rese1_1_Review():
    df_key = pd.read_csv("Kamoku/卒業研究１/卒業研究１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/卒業研究１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/卒業研究１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/卒業研究１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究１/grad_rese1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/grad_rese1_1_mihyouka_Review", methods=["POST"])
def grad_rese1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/卒業研究１/卒業研究１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/卒業研究１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/卒業研究１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/卒業研究１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/卒業研究１/grad_rese1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/grad_rese1_1_video',methods =["post"])
def grad_rese1_1_video():
    df_key = pd.read_csv("Kamoku/卒業研究１/卒業研究１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/卒業研究１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究１/grad_rese1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/grad_rese1_1_mihyouka_video',methods =["post"])
def grad_rese1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/卒業研究１/卒業研究１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/卒業研究１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究１/grad_rese1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/grad_rese1_2")
def grad_rese1_2():
    df_key = pd.read_csv("Kamoku/卒業研究１/卒業研究１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/卒業研究１/grad_rese1_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/grad_rese1_2_Review',methods = ["post"])
def grad_rese1_2_Review():
    df_key = pd.read_csv("Kamoku/卒業研究１/卒業研究１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/卒業研究１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/卒業研究１/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/卒業研究１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究１/grad_rese1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/grad_rese1_2_mihyouka_Review", methods=["POST"])
def grad_rese1_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/卒業研究１/卒業研究１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/卒業研究１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/卒業研究１/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/卒業研究１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/卒業研究１/grad_rese1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/grad_rese1_2_video',methods =["post"])
def grad_rese1_2_video():
    df_key = pd.read_csv("Kamoku/卒業研究１/卒業研究１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/卒業研究１/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究１/grad_rese1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/grad_rese1_2_mihyouka_video',methods =["post"])
def grad_rese1_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/卒業研究１/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究１/grad_rese1_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/grad_rese1_3")
def grad_rese1_3():
    df_key = pd.read_csv("Kamoku/卒業研究１/卒業研究１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/卒業研究１/grad_rese1_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/grad_rese1_3_Review',methods = ["post"])
def grad_rese1_3_Review():
    df_key = pd.read_csv("Kamoku/卒業研究１/卒業研究１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/卒業研究１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/卒業研究１/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/卒業研究１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究１/grad_rese1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/grad_rese1_3_mihyouka_Review", methods=["POST"])
def grad_rese1_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/卒業研究１/卒業研究１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/卒業研究１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/卒業研究１/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/卒業研究１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/卒業研究１/grad_rese1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/grad_rese1_3_video',methods =["post"])
def grad_rese1_3_video():
    df_key = pd.read_csv("Kamoku/卒業研究１/卒業研究１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/卒業研究１/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究１/grad_rese1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/grad_rese1_3_mihyouka_video',methods =["post"])
def grad_rese1_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/卒業研究１/卒業研究１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/卒業研究１/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/卒業研究１/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究１/grad_rese1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )




################################################################################################
#############################################卒業研究２############################
################################################################################################
@app.route("/grad_rese")
def grad_rese():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/卒業研究２/grad_rese_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/grad_rese1")
def grad_rese1():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/卒業研究２/grad_rese1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/grad_rese1_Review',methods = ["post"])
def grad_rese1_Review():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/卒業研究２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究２/grad_rese1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/grad_rese1_mihyouka_Review", methods=["POST"])
def grad_rese1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/卒業研究２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/卒業研究２/grad_rese1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/grad_rese1_video',methods =["post"])
def grad_rese1_video():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/卒業研究２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究２/grad_rese1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/grad_rese1_mihyouka_video',methods =["post"])
def grad_rese1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/卒業研究２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究２/grad_rese1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/grad_rese2")
def grad_rese2():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/卒業研究２/grad_rese2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/grad_rese2_Review',methods = ["post"])
def grad_rese2_Review():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/卒業研究２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究２/grad_rese2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/grad_rese2_mihyouka_Review", methods=["POST"])
def grad_rese2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/卒業研究２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/卒業研究２/grad_rese2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/grad_rese2_video',methods =["post"])
def grad_rese2_video():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/卒業研究２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究２/grad_rese2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/grad_rese2_mihyouka_video',methods =["post"])
def grad_rese2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/卒業研究２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究２/grad_rese2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/grad_rese3")
def grad_rese3():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/卒業研究２/grad_rese3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/grad_rese3_Review',methods = ["post"])
def grad_rese3_Review():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/卒業研究２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究２/grad_rese3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/grad_rese3_mihyouka_Review", methods=["POST"])
def grad_rese3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/卒業研究２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/卒業研究２/grad_rese3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/grad_rese3_video',methods =["post"])
def grad_rese3_video():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/卒業研究２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究２/grad_rese3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/grad_rese3_mihyouka_video',methods =["post"])
def grad_rese3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/卒業研究２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究２/grad_rese3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/grad_rese4")
def grad_rese4():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/卒業研究２/grad_rese4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/grad_rese4_Review',methods = ["post"])
def grad_rese4_Review():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/卒業研究２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究２/grad_rese4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/grad_rese4_mihyouka_Review", methods=["POST"])
def grad_rese4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/卒業研究２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/卒業研究２/grad_rese4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/grad_rese4_video',methods =["post"])
def grad_rese4_video():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/卒業研究２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究２/grad_rese4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/grad_rese4_mihyouka_video',methods =["post"])
def grad_rese4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/卒業研究２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究２/grad_rese4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/grad_rese5")
def grad_rese5():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/卒業研究２/grad_rese5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/grad_rese5_Review',methods = ["post"])
def grad_rese5_Review():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/卒業研究２/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究２/grad_rese5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/grad_rese5_mihyouka_Review", methods=["POST"])
def grad_rese5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/卒業研究２/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/卒業研究２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/卒業研究２/grad_rese5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/grad_rese5_video',methods =["post"])
def grad_rese5_video():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/卒業研究２/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究２/grad_rese5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/grad_rese5_mihyouka_video',methods =["post"])
def grad_rese5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/卒業研究２/卒業研究２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/卒業研究２/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/卒業研究２/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/卒業研究２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/卒業研究２/grad_rese5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################待ち行列理論と性能解析############################
################################################################################################
@app.route("/queueing")
def queueing():
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/待ち行列理論と性能解析/queueing_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/queueing1")
def queueing1():
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/待ち行列理論と性能解析/queueing1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/queueing1_Review',methods = ["post"])
def queueing1_Review():
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/待ち行列理論と性能解析/queueing1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/queueing1_mihyouka_Review", methods=["POST"])
def queueing1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/待ち行列理論と性能解析/queueing1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/queueing1_video',methods =["post"])
def queueing1_video():
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/待ち行列理論と性能解析/queueing1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/queueing1_mihyouka_video',methods =["post"])
def queueing1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/待ち行列理論と性能解析/queueing1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/queueing2")
def queueing2():
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/待ち行列理論と性能解析/queueing2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/queueing2_Review',methods = ["post"])
def queueing2_Review():
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/待ち行列理論と性能解析/queueing2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/queueing2_mihyouka_Review", methods=["POST"])
def queueing2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/待ち行列理論と性能解析/queueing2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/queueing2_video',methods =["post"])
def queueing2_video():
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/待ち行列理論と性能解析/queueing2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/queueing2_mihyouka_video',methods =["post"])
def queueing2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/待ち行列理論と性能解析/queueing2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/queueing3")
def queueing3():
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/待ち行列理論と性能解析/queueing3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/queueing3_Review',methods = ["post"])
def queueing3_Review():
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/待ち行列理論と性能解析/queueing3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/queueing3_mihyouka_Review", methods=["POST"])
def queueing3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/待ち行列理論と性能解析/queueing3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/queueing3_video',methods =["post"])
def queueing3_video():
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/待ち行列理論と性能解析/queueing3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/queueing3_mihyouka_video',methods =["post"])
def queueing3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/待ち行列理論と性能解析/queueing3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/queueing4")
def queueing4():
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/待ち行列理論と性能解析/queueing4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/queueing4_Review',methods = ["post"])
def queueing4_Review():
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/待ち行列理論と性能解析/queueing4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/queueing4_mihyouka_Review", methods=["POST"])
def queueing4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/待ち行列理論と性能解析/queueing4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/queueing4_video',methods =["post"])
def queueing4_video():
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/待ち行列理論と性能解析/queueing4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/queueing4_mihyouka_video',methods =["post"])
def queueing4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/待ち行列理論と性能解析/待ち行列理論と性能解析.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/待ち行列理論と性能解析/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/待ち行列理論と性能解析/queueing4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################中国語１############################
################################################################################################
@app.route("/china1_")
def china1_():
    df_key = pd.read_csv("Kamoku/中国語１/中国語１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/中国語１/china1__syr.html', 
                            key_word1 = keyword[0]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/china1_1")
def china1_1():
    df_key = pd.read_csv("Kamoku/中国語１/中国語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/中国語１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/中国語１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/中国語１/china1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/china1_1_Review',methods = ["post"])
def china1_1_Review():
    df_key = pd.read_csv("Kamoku/中国語１/中国語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/中国語１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/中国語１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/中国語１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/中国語１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/中国語１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/中国語１/china1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/china1_1_mihyouka_Review", methods=["POST"])
def china1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/中国語１/中国語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/中国語１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/中国語１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/中国語１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/中国語１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/中国語１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/中国語１/china1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/china1_1_video',methods =["post"])
def china1_1_video():
    df_key = pd.read_csv("Kamoku/中国語１/中国語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/中国語１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/中国語１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/中国語１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/中国語１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/中国語１/china1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/china1_1_mihyouka_video',methods =["post"])
def china1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/中国語１/中国語１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/中国語１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/中国語１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/中国語１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/中国語１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/中国語１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/中国語１/china1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


################################################################################################
#############################################中国語２############################
################################################################################################
@app.route("/china2_")
def china2_():
    df_key = pd.read_csv("Kamoku/中国語２/中国語２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/中国語２/china2__syr.html', 
                            key_word1 = keyword[0]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/china2_1")
def china2_1():
    df_key = pd.read_csv("Kamoku/中国語２/中国語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/中国語２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/中国語２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/中国語２/china2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/china2_1_Review',methods = ["post"])
def china2_1_Review():
    df_key = pd.read_csv("Kamoku/中国語２/中国語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/中国語２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/中国語２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/中国語２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/中国語２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/中国語２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/中国語２/china2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/china2_1_mihyouka_Review", methods=["POST"])
def china2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/中国語２/中国語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/中国語２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/中国語２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/中国語２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/中国語２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/中国語２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/中国語２/china2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/china2_1_video',methods =["post"])
def china2_1_video():
    df_key = pd.read_csv("Kamoku/中国語２/中国語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/中国語２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/中国語２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/中国語２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/中国語２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/中国語２/china2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/china2_1_mihyouka_video',methods =["post"])
def china2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/中国語２/中国語２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/中国語２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/中国語２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/中国語２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/中国語２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/中国語２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/中国語２/china2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )




################################################################################################
#############################################通信方式############################
################################################################################################
@app.route("/commu_sys")
def commu_sys():
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/通信方式/commu_sys_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/commu_sys1")
def commu_sys1():
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/通信方式/commu_sys1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/commu_sys1_Review',methods = ["post"])
def commu_sys1_Review():
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/通信方式/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/通信方式/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/通信方式/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/通信方式/commu_sys1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/commu_sys1_mihyouka_Review", methods=["POST"])
def commu_sys1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/通信方式/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/通信方式/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/通信方式/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/通信方式/commu_sys1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/commu_sys1_video',methods =["post"])
def commu_sys1_video():
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/通信方式/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/通信方式/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/通信方式/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/通信方式/commu_sys1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/commu_sys1_mihyouka_video',methods =["post"])
def commu_sys1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/通信方式/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/通信方式/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/通信方式/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/通信方式/commu_sys1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/commu_sys2")
def commu_sys2():
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/通信方式/commu_sys2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/commu_sys2_Review',methods = ["post"])
def commu_sys2_Review():
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/通信方式/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/通信方式/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/通信方式/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/通信方式/commu_sys2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/commu_sys2_mihyouka_Review", methods=["POST"])
def commu_sys2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/通信方式/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/通信方式/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/通信方式/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/通信方式/commu_sys2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/commu_sys2_video',methods =["post"])
def commu_sys2_video():
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/通信方式/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/通信方式/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/通信方式/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/通信方式/commu_sys2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/commu_sys2_mihyouka_video',methods =["post"])
def commu_sys2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/通信方式/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/通信方式/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/通信方式/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/通信方式/commu_sys2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/commu_sys3")
def commu_sys3():
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/通信方式/commu_sys3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/commu_sys3_Review',methods = ["post"])
def commu_sys3_Review():
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/通信方式/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/通信方式/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/通信方式/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/通信方式/commu_sys3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/commu_sys3_mihyouka_Review", methods=["POST"])
def commu_sys3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/通信方式/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/通信方式/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/通信方式/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/通信方式/commu_sys3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/commu_sys3_video',methods =["post"])
def commu_sys3_video():
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/通信方式/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/通信方式/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/通信方式/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/通信方式/commu_sys3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/commu_sys3_mihyouka_video',methods =["post"])
def commu_sys3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/通信方式/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/通信方式/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/通信方式/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/通信方式/commu_sys3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/commu_sys4")
def commu_sys4():
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/通信方式/commu_sys4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/commu_sys4_Review',methods = ["post"])
def commu_sys4_Review():
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/通信方式/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/通信方式/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/通信方式/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/通信方式/commu_sys4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/commu_sys4_mihyouka_Review", methods=["POST"])
def commu_sys4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/通信方式/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/通信方式/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/通信方式/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/通信方式/commu_sys4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/commu_sys4_video',methods =["post"])
def commu_sys4_video():
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/通信方式/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/通信方式/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/通信方式/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/通信方式/commu_sys4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/commu_sys4_mihyouka_video',methods =["post"])
def commu_sys4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/通信方式/通信方式.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/通信方式/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/通信方式/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/通信方式/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/通信方式/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/通信方式/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/通信方式/commu_sys4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################哲学############################
################################################################################################
@app.route("/philo")
def philo():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/哲学/philo_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/philo1")
def philo1():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/哲学/philo1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/philo1_Review',methods = ["post"])
def philo1_Review():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/哲学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/philo1_mihyouka_Review", methods=["POST"])
def philo1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/哲学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/哲学/philo1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/philo1_video',methods =["post"])
def philo1_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/哲学/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/philo1_mihyouka_video',methods =["post"])
def philo1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/哲学/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/philo2")
def philo2():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/哲学/philo2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/philo2_Review',methods = ["post"])
def philo2_Review():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/哲学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/philo2_mihyouka_Review", methods=["POST"])
def philo2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/哲学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/哲学/philo2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/philo2_video',methods =["post"])
def philo2_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/哲学/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/philo2_mihyouka_video',methods =["post"])
def philo2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/哲学/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/philo3")
def philo3():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/哲学/philo3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/philo3_Review',methods = ["post"])
def philo3_Review():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/哲学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/philo3_mihyouka_Review", methods=["POST"])
def philo3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/哲学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/哲学/philo3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/philo3_video',methods =["post"])
def philo3_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/哲学/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/philo3_mihyouka_video',methods =["post"])
def philo3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/哲学/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/philo4")
def philo4():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/哲学/philo4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/philo4_Review',methods = ["post"])
def philo4_Review():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/哲学/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/philo4_mihyouka_Review", methods=["POST"])
def philo4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/哲学/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/哲学/philo4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/philo4_video',methods =["post"])
def philo4_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/哲学/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/philo4_mihyouka_video',methods =["post"])
def philo4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/哲学/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/philo5")
def philo5():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/哲学/philo5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/philo5_Review',methods = ["post"])
def philo5_Review():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/哲学/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/philo5_mihyouka_Review", methods=["POST"])
def philo5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/哲学/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/哲学/philo5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/philo5_video',methods =["post"])
def philo5_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/哲学/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/philo5_mihyouka_video',methods =["post"])
def philo5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/哲学/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/philo6")
def philo6():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/哲学/philo6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/philo6_Review',methods = ["post"])
def philo6_Review():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/哲学/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/philo6_mihyouka_Review", methods=["POST"])
def philo6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/哲学/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/哲学/philo6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/philo6_video',methods =["post"])
def philo6_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/哲学/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/philo6_mihyouka_video',methods =["post"])
def philo6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/哲学/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/philo7")
def philo7():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/哲学/philo7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/philo7_Review',methods = ["post"])
def philo7_Review():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/哲学/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/philo7_mihyouka_Review", methods=["POST"])
def philo7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/哲学/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/哲学/philo7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/philo7_video',methods =["post"])
def philo7_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/哲学/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/philo7_mihyouka_video',methods =["post"])
def philo7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/哲学/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/philo8")
def philo8():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/哲学/philo8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/philo8_Review',methods = ["post"])
def philo8_Review():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/哲学/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/philo8_mihyouka_Review", methods=["POST"])
def philo8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/哲学/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/哲学/philo8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/philo8_video',methods =["post"])
def philo8_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/哲学/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/philo8_mihyouka_video',methods =["post"])
def philo8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/哲学/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/philo9")
def philo9():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/哲学/philo9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/philo9_Review',methods = ["post"])
def philo9_Review():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/哲学/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/philo9_mihyouka_Review", methods=["POST"])
def philo9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/哲学/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/哲学/philo9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/philo9_video',methods =["post"])
def philo9_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/哲学/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/philo9_mihyouka_video',methods =["post"])
def philo9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/哲学/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/philo10")
def philo10():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/哲学/philo10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/philo10_Review',methods = ["post"])
def philo10_Review():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/哲学/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/philo10_mihyouka_Review", methods=["POST"])
def philo10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/哲学/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/哲学/philo10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/philo10_video',methods =["post"])
def philo10_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/哲学/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/philo10_mihyouka_video',methods =["post"])
def philo10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/哲学/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/philo11")
def philo11():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/哲学/philo11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/philo11_Review',methods = ["post"])
def philo11_Review():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/哲学/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/philo11_mihyouka_Review", methods=["POST"])
def philo11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/哲学/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/哲学/philo11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/philo11_video',methods =["post"])
def philo11_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/哲学/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/philo11_mihyouka_video',methods =["post"])
def philo11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/哲学/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/philo12")
def philo12():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/哲学/philo12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/philo12_Review',methods = ["post"])
def philo12_Review():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/哲学/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/philo12_mihyouka_Review", methods=["POST"])
def philo12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/哲学/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/哲学/philo12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/philo12_video',methods =["post"])
def philo12_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/哲学/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/philo12_mihyouka_video',methods =["post"])
def philo12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/哲学/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/philo13")
def philo13():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/哲学/philo13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/philo13_Review',methods = ["post"])
def philo13_Review():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/哲学/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/philo13_mihyouka_Review", methods=["POST"])
def philo13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/哲学/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/哲学/philo13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/philo13_video',methods =["post"])
def philo13_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/哲学/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/philo13_mihyouka_video',methods =["post"])
def philo13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/哲学/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/philo14")
def philo14():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/哲学/philo14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/philo14_Review',methods = ["post"])
def philo14_Review():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/哲学/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/philo14_mihyouka_Review", methods=["POST"])
def philo14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/哲学/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/哲学/philo14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/philo14_video',methods =["post"])
def philo14_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/哲学/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/philo14_mihyouka_video',methods =["post"])
def philo14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/哲学/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/philo15")
def philo15():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/哲学/philo15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/philo15_Review',methods = ["post"])
def philo15_Review():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/哲学/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/philo15_mihyouka_Review", methods=["POST"])
def philo15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/哲学/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/哲学/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/哲学/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/哲学/philo15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/philo15_video',methods =["post"])
def philo15_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/哲学/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/philo15_mihyouka_video',methods =["post"])
def philo15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/哲学/哲学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/哲学/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/哲学/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/哲学/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/哲学/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/哲学/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/哲学/philo15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )




################################################################################################
#############################################電気回路############################
################################################################################################
@app.route("/elec_circuit")
def elec_circuit():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/電気回路/elec_circuit_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/elec_circuit1")
def elec_circuit1():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電気回路/elec_circuit1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/elec_circuit1_Review',methods = ["post"])
def elec_circuit1_Review():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/elec_circuit1_mihyouka_Review", methods=["POST"])
def elec_circuit1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電気回路/elec_circuit1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/elec_circuit1_video',methods =["post"])
def elec_circuit1_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電気回路/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/elec_circuit1_mihyouka_video',methods =["post"])
def elec_circuit1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電気回路/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/elec_circuit2")
def elec_circuit2():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電気回路/elec_circuit2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/elec_circuit2_Review',methods = ["post"])
def elec_circuit2_Review():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/elec_circuit2_mihyouka_Review", methods=["POST"])
def elec_circuit2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電気回路/elec_circuit2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/elec_circuit2_video',methods =["post"])
def elec_circuit2_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電気回路/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/elec_circuit2_mihyouka_video',methods =["post"])
def elec_circuit2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電気回路/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/elec_circuit3")
def elec_circuit3():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電気回路/elec_circuit3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/elec_circuit3_Review',methods = ["post"])
def elec_circuit3_Review():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/elec_circuit3_mihyouka_Review", methods=["POST"])
def elec_circuit3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電気回路/elec_circuit3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/elec_circuit3_video',methods =["post"])
def elec_circuit3_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電気回路/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/elec_circuit3_mihyouka_video',methods =["post"])
def elec_circuit3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電気回路/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/elec_circuit4")
def elec_circuit4():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電気回路/elec_circuit4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/elec_circuit4_Review',methods = ["post"])
def elec_circuit4_Review():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/elec_circuit4_mihyouka_Review", methods=["POST"])
def elec_circuit4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電気回路/elec_circuit4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/elec_circuit4_video',methods =["post"])
def elec_circuit4_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電気回路/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/elec_circuit4_mihyouka_video',methods =["post"])
def elec_circuit4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電気回路/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/elec_circuit5")
def elec_circuit5():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電気回路/elec_circuit5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/elec_circuit5_Review',methods = ["post"])
def elec_circuit5_Review():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/elec_circuit5_mihyouka_Review", methods=["POST"])
def elec_circuit5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電気回路/elec_circuit5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/elec_circuit5_video',methods =["post"])
def elec_circuit5_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電気回路/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/elec_circuit5_mihyouka_video',methods =["post"])
def elec_circuit5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電気回路/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/elec_circuit6")
def elec_circuit6():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電気回路/elec_circuit6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/elec_circuit6_Review',methods = ["post"])
def elec_circuit6_Review():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/elec_circuit6_mihyouka_Review", methods=["POST"])
def elec_circuit6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電気回路/elec_circuit6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/elec_circuit6_video',methods =["post"])
def elec_circuit6_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電気回路/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/elec_circuit6_mihyouka_video',methods =["post"])
def elec_circuit6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電気回路/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/elec_circuit7")
def elec_circuit7():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電気回路/elec_circuit7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/elec_circuit7_Review',methods = ["post"])
def elec_circuit7_Review():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/elec_circuit7_mihyouka_Review", methods=["POST"])
def elec_circuit7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電気回路/elec_circuit7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/elec_circuit7_video',methods =["post"])
def elec_circuit7_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電気回路/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/elec_circuit7_mihyouka_video',methods =["post"])
def elec_circuit7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電気回路/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/elec_circuit8")
def elec_circuit8():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電気回路/elec_circuit8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/elec_circuit8_Review',methods = ["post"])
def elec_circuit8_Review():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/elec_circuit8_mihyouka_Review", methods=["POST"])
def elec_circuit8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電気回路/elec_circuit8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/elec_circuit8_video',methods =["post"])
def elec_circuit8_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電気回路/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/elec_circuit8_mihyouka_video',methods =["post"])
def elec_circuit8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電気回路/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/elec_circuit9")
def elec_circuit9():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電気回路/elec_circuit9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/elec_circuit9_Review',methods = ["post"])
def elec_circuit9_Review():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/elec_circuit9_mihyouka_Review", methods=["POST"])
def elec_circuit9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電気回路/elec_circuit9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/elec_circuit9_video',methods =["post"])
def elec_circuit9_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電気回路/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/elec_circuit9_mihyouka_video',methods =["post"])
def elec_circuit9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電気回路/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/elec_circuit10")
def elec_circuit10():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電気回路/elec_circuit10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/elec_circuit10_Review',methods = ["post"])
def elec_circuit10_Review():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/elec_circuit10_mihyouka_Review", methods=["POST"])
def elec_circuit10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電気回路/elec_circuit10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/elec_circuit10_video',methods =["post"])
def elec_circuit10_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電気回路/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/elec_circuit10_mihyouka_video',methods =["post"])
def elec_circuit10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電気回路/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/elec_circuit11")
def elec_circuit11():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電気回路/elec_circuit11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/elec_circuit11_Review',methods = ["post"])
def elec_circuit11_Review():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/elec_circuit11_mihyouka_Review", methods=["POST"])
def elec_circuit11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電気回路/elec_circuit11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/elec_circuit11_video',methods =["post"])
def elec_circuit11_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電気回路/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/elec_circuit11_mihyouka_video',methods =["post"])
def elec_circuit11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電気回路/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/elec_circuit12")
def elec_circuit12():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電気回路/elec_circuit12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/elec_circuit12_Review',methods = ["post"])
def elec_circuit12_Review():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/elec_circuit12_mihyouka_Review", methods=["POST"])
def elec_circuit12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電気回路/elec_circuit12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/elec_circuit12_video',methods =["post"])
def elec_circuit12_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電気回路/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/elec_circuit12_mihyouka_video',methods =["post"])
def elec_circuit12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電気回路/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/elec_circuit13")
def elec_circuit13():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電気回路/elec_circuit13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/elec_circuit13_Review',methods = ["post"])
def elec_circuit13_Review():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/elec_circuit13_mihyouka_Review", methods=["POST"])
def elec_circuit13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電気回路/elec_circuit13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/elec_circuit13_video',methods =["post"])
def elec_circuit13_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電気回路/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/elec_circuit13_mihyouka_video',methods =["post"])
def elec_circuit13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電気回路/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/elec_circuit14")
def elec_circuit14():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電気回路/elec_circuit14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/elec_circuit14_Review',methods = ["post"])
def elec_circuit14_Review():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/elec_circuit14_mihyouka_Review", methods=["POST"])
def elec_circuit14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電気回路/elec_circuit14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/elec_circuit14_video',methods =["post"])
def elec_circuit14_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電気回路/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/elec_circuit14_mihyouka_video',methods =["post"])
def elec_circuit14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電気回路/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/elec_circuit15")
def elec_circuit15():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電気回路/elec_circuit15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/elec_circuit15_Review',methods = ["post"])
def elec_circuit15_Review():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/elec_circuit15_mihyouka_Review", methods=["POST"])
def elec_circuit15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電気回路/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電気回路/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電気回路/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電気回路/elec_circuit15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/elec_circuit15_video',methods =["post"])
def elec_circuit15_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電気回路/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/elec_circuit15_mihyouka_video',methods =["post"])
def elec_circuit15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電気回路/電気回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電気回路/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電気回路/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電気回路/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電気回路/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電気回路/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電気回路/elec_circuit15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################電子回路############################
################################################################################################
@app.route("/electron_circuit")
def electron_circuit():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/電子回路/electron_circuit_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/electron_circuit1")
def electron_circuit1():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電子回路/electron_circuit1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/electron_circuit1_Review',methods = ["post"])
def electron_circuit1_Review():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電子回路/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電子回路/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電子回路/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電子回路/electron_circuit1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/electron_circuit1_mihyouka_Review", methods=["POST"])
def electron_circuit1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電子回路/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電子回路/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電子回路/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電子回路/electron_circuit1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/electron_circuit1_video',methods =["post"])
def electron_circuit1_video():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電子回路/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電子回路/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電子回路/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電子回路/electron_circuit1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/electron_circuit1_mihyouka_video',methods =["post"])
def electron_circuit1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電子回路/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電子回路/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電子回路/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電子回路/electron_circuit1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/electron_circuit2")
def electron_circuit2():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電子回路/electron_circuit2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/electron_circuit2_Review',methods = ["post"])
def electron_circuit2_Review():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電子回路/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電子回路/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電子回路/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電子回路/electron_circuit2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/electron_circuit2_mihyouka_Review", methods=["POST"])
def electron_circuit2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電子回路/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電子回路/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電子回路/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電子回路/electron_circuit2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/electron_circuit2_video',methods =["post"])
def electron_circuit2_video():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電子回路/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電子回路/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電子回路/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電子回路/electron_circuit2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/electron_circuit2_mihyouka_video',methods =["post"])
def electron_circuit2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電子回路/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電子回路/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電子回路/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電子回路/electron_circuit2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/electron_circuit3")
def electron_circuit3():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電子回路/electron_circuit3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/electron_circuit3_Review',methods = ["post"])
def electron_circuit3_Review():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電子回路/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電子回路/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電子回路/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電子回路/electron_circuit3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/electron_circuit3_mihyouka_Review", methods=["POST"])
def electron_circuit3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電子回路/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電子回路/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電子回路/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電子回路/electron_circuit3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/electron_circuit3_video',methods =["post"])
def electron_circuit3_video():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電子回路/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電子回路/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電子回路/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電子回路/electron_circuit3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/electron_circuit3_mihyouka_video',methods =["post"])
def electron_circuit3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電子回路/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電子回路/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電子回路/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電子回路/electron_circuit3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/electron_circuit4")
def electron_circuit4():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電子回路/electron_circuit4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/electron_circuit4_Review',methods = ["post"])
def electron_circuit4_Review():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電子回路/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電子回路/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電子回路/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電子回路/electron_circuit4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/electron_circuit4_mihyouka_Review", methods=["POST"])
def electron_circuit4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電子回路/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電子回路/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電子回路/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電子回路/electron_circuit4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/electron_circuit4_video',methods =["post"])
def electron_circuit4_video():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電子回路/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電子回路/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電子回路/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電子回路/electron_circuit4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/electron_circuit4_mihyouka_video',methods =["post"])
def electron_circuit4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電子回路/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電子回路/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電子回路/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電子回路/electron_circuit4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/electron_circuit5")
def electron_circuit5():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/電子回路/electron_circuit5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/electron_circuit5_Review',methods = ["post"])
def electron_circuit5_Review():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/電子回路/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電子回路/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/電子回路/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電子回路/electron_circuit5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/electron_circuit5_mihyouka_Review", methods=["POST"])
def electron_circuit5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/電子回路/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/電子回路/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/電子回路/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/電子回路/electron_circuit5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/electron_circuit5_video',methods =["post"])
def electron_circuit5_video():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/電子回路/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/電子回路/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電子回路/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電子回路/electron_circuit5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/electron_circuit5_mihyouka_video',methods =["post"])
def electron_circuit5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/電子回路/電子回路.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/電子回路/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/電子回路/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/電子回路/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/電子回路/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/電子回路/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/電子回路/electron_circuit5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################日本語表現法　前期############################
################################################################################################
@app.route("/japan_express_1st")
def japan_express_1st():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/日本語表現法　前期/japan_express_1st_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/japan_express_1st1")
def japan_express_1st1():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　前期/japan_express_1st1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_1st1_Review',methods = ["post"])
def japan_express_1st1_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_1st1_mihyouka_Review", methods=["POST"])
def japan_express_1st1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　前期/japan_express_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_1st1_video',methods =["post"])
def japan_express_1st1_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_1st1_mihyouka_video',methods =["post"])
def japan_express_1st1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/japan_express_1st2")
def japan_express_1st2():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　前期/japan_express_1st2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_1st2_Review',methods = ["post"])
def japan_express_1st2_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_1st2_mihyouka_Review", methods=["POST"])
def japan_express_1st2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　前期/japan_express_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_1st2_video',methods =["post"])
def japan_express_1st2_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_1st2_mihyouka_video',methods =["post"])
def japan_express_1st2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/japan_express_1st3")
def japan_express_1st3():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　前期/japan_express_1st3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_1st3_Review',methods = ["post"])
def japan_express_1st3_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_1st3_mihyouka_Review", methods=["POST"])
def japan_express_1st3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　前期/japan_express_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_1st3_video',methods =["post"])
def japan_express_1st3_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_1st3_mihyouka_video',methods =["post"])
def japan_express_1st3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/japan_express_1st4")
def japan_express_1st4():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　前期/japan_express_1st4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_1st4_Review',methods = ["post"])
def japan_express_1st4_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_1st4_mihyouka_Review", methods=["POST"])
def japan_express_1st4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　前期/japan_express_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_1st4_video',methods =["post"])
def japan_express_1st4_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_1st4_mihyouka_video',methods =["post"])
def japan_express_1st4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/japan_express_1st5")
def japan_express_1st5():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　前期/japan_express_1st5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_1st5_Review',methods = ["post"])
def japan_express_1st5_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_1st5_mihyouka_Review", methods=["POST"])
def japan_express_1st5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　前期/japan_express_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_1st5_video',methods =["post"])
def japan_express_1st5_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_1st5_mihyouka_video',methods =["post"])
def japan_express_1st5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/japan_express_1st6")
def japan_express_1st6():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　前期/japan_express_1st6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_1st6_Review',methods = ["post"])
def japan_express_1st6_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_1st6_mihyouka_Review", methods=["POST"])
def japan_express_1st6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　前期/japan_express_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_1st6_video',methods =["post"])
def japan_express_1st6_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_1st6_mihyouka_video',methods =["post"])
def japan_express_1st6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/japan_express_1st7")
def japan_express_1st7():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　前期/japan_express_1st7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_1st7_Review',methods = ["post"])
def japan_express_1st7_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_1st7_mihyouka_Review", methods=["POST"])
def japan_express_1st7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　前期/japan_express_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_1st7_video',methods =["post"])
def japan_express_1st7_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_1st7_mihyouka_video',methods =["post"])
def japan_express_1st7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/japan_express_1st8")
def japan_express_1st8():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　前期/japan_express_1st8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_1st8_Review',methods = ["post"])
def japan_express_1st8_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_1st8_mihyouka_Review", methods=["POST"])
def japan_express_1st8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　前期/japan_express_1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_1st8_video',methods =["post"])
def japan_express_1st8_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_1st8_mihyouka_video',methods =["post"])
def japan_express_1st8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/japan_express_1st9")
def japan_express_1st9():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　前期/japan_express_1st9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_1st9_Review',methods = ["post"])
def japan_express_1st9_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_1st9_mihyouka_Review", methods=["POST"])
def japan_express_1st9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　前期/japan_express_1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_1st9_video',methods =["post"])
def japan_express_1st9_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_1st9_mihyouka_video',methods =["post"])
def japan_express_1st9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　前期/日本語表現法　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　前期/japan_express_1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################日本語表現法　後期############################
################################################################################################
@app.route("/japan_express_2st")
def japan_express_2st():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/日本語表現法　後期/japan_express_2st_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/japan_express_2st1")
def japan_express_2st1():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　後期/japan_express_2st1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_2st1_Review',methods = ["post"])
def japan_express_2st1_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_2st1_mihyouka_Review", methods=["POST"])
def japan_express_2st1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　後期/japan_express_2st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_2st1_video',methods =["post"])
def japan_express_2st1_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_2st1_mihyouka_video',methods =["post"])
def japan_express_2st1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/japan_express_2st2")
def japan_express_2st2():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　後期/japan_express_2st2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_2st2_Review',methods = ["post"])
def japan_express_2st2_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_2st2_mihyouka_Review", methods=["POST"])
def japan_express_2st2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　後期/japan_express_2st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_2st2_video',methods =["post"])
def japan_express_2st2_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_2st2_mihyouka_video',methods =["post"])
def japan_express_2st2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/japan_express_2st3")
def japan_express_2st3():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　後期/japan_express_2st3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_2st3_Review',methods = ["post"])
def japan_express_2st3_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_2st3_mihyouka_Review", methods=["POST"])
def japan_express_2st3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　後期/japan_express_2st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_2st3_video',methods =["post"])
def japan_express_2st3_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_2st3_mihyouka_video',methods =["post"])
def japan_express_2st3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/japan_express_2st4")
def japan_express_2st4():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　後期/japan_express_2st4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_2st4_Review',methods = ["post"])
def japan_express_2st4_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_2st4_mihyouka_Review", methods=["POST"])
def japan_express_2st4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　後期/japan_express_2st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_2st4_video',methods =["post"])
def japan_express_2st4_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_2st4_mihyouka_video',methods =["post"])
def japan_express_2st4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/japan_express_2st5")
def japan_express_2st5():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　後期/japan_express_2st5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_2st5_Review',methods = ["post"])
def japan_express_2st5_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_2st5_mihyouka_Review", methods=["POST"])
def japan_express_2st5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　後期/japan_express_2st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_2st5_video',methods =["post"])
def japan_express_2st5_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_2st5_mihyouka_video',methods =["post"])
def japan_express_2st5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/japan_express_2st6")
def japan_express_2st6():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　後期/japan_express_2st6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_2st6_Review',methods = ["post"])
def japan_express_2st6_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_2st6_mihyouka_Review", methods=["POST"])
def japan_express_2st6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　後期/japan_express_2st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_2st6_video',methods =["post"])
def japan_express_2st6_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_2st6_mihyouka_video',methods =["post"])
def japan_express_2st6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/japan_express_2st7")
def japan_express_2st7():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　後期/japan_express_2st7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_2st7_Review',methods = ["post"])
def japan_express_2st7_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_2st7_mihyouka_Review", methods=["POST"])
def japan_express_2st7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　後期/japan_express_2st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_2st7_video',methods =["post"])
def japan_express_2st7_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_2st7_mihyouka_video',methods =["post"])
def japan_express_2st7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/japan_express_2st8")
def japan_express_2st8():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　後期/japan_express_2st8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_2st8_Review',methods = ["post"])
def japan_express_2st8_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_2st8_mihyouka_Review", methods=["POST"])
def japan_express_2st8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　後期/japan_express_2st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_2st8_video',methods =["post"])
def japan_express_2st8_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_2st8_mihyouka_video',methods =["post"])
def japan_express_2st8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/japan_express_2st9")
def japan_express_2st9():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本語表現法　後期/japan_express_2st9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_express_2st9_Review',methods = ["post"])
def japan_express_2st9_Review():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_express_2st9_mihyouka_Review", methods=["POST"])
def japan_express_2st9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本語表現法　後期/japan_express_2st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_express_2st9_video',methods =["post"])
def japan_express_2st9_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_express_2st9_mihyouka_video',methods =["post"])
def japan_express_2st9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本語表現法　後期/日本語表現法　後期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本語表現法　後期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本語表現法　後期/japan_express_2st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################日本国憲法############################
################################################################################################
@app.route("/japan_const")
def japan_const():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/日本国憲法/japan_const_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/japan_const1")
def japan_const1():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本国憲法/japan_const1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_const1_Review',methods = ["post"])
def japan_const1_Review():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_const1_mihyouka_Review", methods=["POST"])
def japan_const1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本国憲法/japan_const1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_const1_video',methods =["post"])
def japan_const1_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_const1_mihyouka_video',methods =["post"])
def japan_const1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/japan_const2")
def japan_const2():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本国憲法/japan_const2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_const2_Review',methods = ["post"])
def japan_const2_Review():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_const2_mihyouka_Review", methods=["POST"])
def japan_const2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本国憲法/japan_const2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_const2_video',methods =["post"])
def japan_const2_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_const2_mihyouka_video',methods =["post"])
def japan_const2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/japan_const3")
def japan_const3():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本国憲法/japan_const3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_const3_Review',methods = ["post"])
def japan_const3_Review():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_const3_mihyouka_Review", methods=["POST"])
def japan_const3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本国憲法/japan_const3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_const3_video',methods =["post"])
def japan_const3_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_const3_mihyouka_video',methods =["post"])
def japan_const3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/japan_const4")
def japan_const4():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本国憲法/japan_const4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_const4_Review',methods = ["post"])
def japan_const4_Review():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_const4_mihyouka_Review", methods=["POST"])
def japan_const4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本国憲法/japan_const4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_const4_video',methods =["post"])
def japan_const4_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_const4_mihyouka_video',methods =["post"])
def japan_const4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/japan_const5")
def japan_const5():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本国憲法/japan_const5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_const5_Review',methods = ["post"])
def japan_const5_Review():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_const5_mihyouka_Review", methods=["POST"])
def japan_const5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本国憲法/japan_const5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_const5_video',methods =["post"])
def japan_const5_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_const5_mihyouka_video',methods =["post"])
def japan_const5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/japan_const6")
def japan_const6():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本国憲法/japan_const6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_const6_Review',methods = ["post"])
def japan_const6_Review():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_const6_mihyouka_Review", methods=["POST"])
def japan_const6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本国憲法/japan_const6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_const6_video',methods =["post"])
def japan_const6_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_const6_mihyouka_video',methods =["post"])
def japan_const6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/japan_const7")
def japan_const7():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本国憲法/japan_const7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_const7_Review',methods = ["post"])
def japan_const7_Review():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_const7_mihyouka_Review", methods=["POST"])
def japan_const7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本国憲法/japan_const7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_const7_video',methods =["post"])
def japan_const7_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_const7_mihyouka_video',methods =["post"])
def japan_const7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/japan_const8")
def japan_const8():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本国憲法/japan_const8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_const8_Review',methods = ["post"])
def japan_const8_Review():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_const8_mihyouka_Review", methods=["POST"])
def japan_const8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本国憲法/japan_const8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_const8_video',methods =["post"])
def japan_const8_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_const8_mihyouka_video',methods =["post"])
def japan_const8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/japan_const9")
def japan_const9():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本国憲法/japan_const9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_const9_Review',methods = ["post"])
def japan_const9_Review():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_const9_mihyouka_Review", methods=["POST"])
def japan_const9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本国憲法/japan_const9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_const9_video',methods =["post"])
def japan_const9_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_const9_mihyouka_video',methods =["post"])
def japan_const9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/japan_const10")
def japan_const10():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本国憲法/japan_const10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_const10_Review',methods = ["post"])
def japan_const10_Review():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_const10_mihyouka_Review", methods=["POST"])
def japan_const10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本国憲法/japan_const10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_const10_video',methods =["post"])
def japan_const10_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_const10_mihyouka_video',methods =["post"])
def japan_const10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/japan_const11")
def japan_const11():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本国憲法/japan_const11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_const11_Review',methods = ["post"])
def japan_const11_Review():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_const11_mihyouka_Review", methods=["POST"])
def japan_const11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本国憲法/japan_const11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_const11_video',methods =["post"])
def japan_const11_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_const11_mihyouka_video',methods =["post"])
def japan_const11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/japan_const12")
def japan_const12():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本国憲法/japan_const12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_const12_Review',methods = ["post"])
def japan_const12_Review():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_const12_mihyouka_Review", methods=["POST"])
def japan_const12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本国憲法/japan_const12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_const12_video',methods =["post"])
def japan_const12_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_const12_mihyouka_video',methods =["post"])
def japan_const12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/japan_const13")
def japan_const13():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本国憲法/japan_const13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_const13_Review',methods = ["post"])
def japan_const13_Review():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_const13_mihyouka_Review", methods=["POST"])
def japan_const13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本国憲法/japan_const13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_const13_video',methods =["post"])
def japan_const13_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_const13_mihyouka_video',methods =["post"])
def japan_const13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/japan_const14")
def japan_const14():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本国憲法/japan_const14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_const14_Review',methods = ["post"])
def japan_const14_Review():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_const14_mihyouka_Review", methods=["POST"])
def japan_const14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本国憲法/japan_const14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_const14_video',methods =["post"])
def japan_const14_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_const14_mihyouka_video',methods =["post"])
def japan_const14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/japan_const15")
def japan_const15():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/日本国憲法/japan_const15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/japan_const15_Review',methods = ["post"])
def japan_const15_Review():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/japan_const15_mihyouka_Review", methods=["POST"])
def japan_const15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/日本国憲法/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/日本国憲法/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/日本国憲法/japan_const15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/japan_const15_video',methods =["post"])
def japan_const15_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/japan_const15_mihyouka_video',methods =["post"])
def japan_const15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/日本国憲法/日本国憲法.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/日本国憲法/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/日本国憲法/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/日本国憲法/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/日本国憲法/japan_const15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################比較文化学１　前期############################
################################################################################################
@app.route("/compare1_1st")
def compare1_1st():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/比較文化学１　前期/compare1_1st_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/compare1_1st1")
def compare1_1st1():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学１　前期/compare1_1st1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare1_1st1_Review',methods = ["post"])
def compare1_1st1_Review():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare1_1st1_mihyouka_Review", methods=["POST"])
def compare1_1st1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学１　前期/compare1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare1_1st1_video',methods =["post"])
def compare1_1st1_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare1_1st1_mihyouka_video',methods =["post"])
def compare1_1st1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/compare1_1st2")
def compare1_1st2():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学１　前期/compare1_1st2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare1_1st2_Review',methods = ["post"])
def compare1_1st2_Review():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare1_1st2_mihyouka_Review", methods=["POST"])
def compare1_1st2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学１　前期/compare1_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare1_1st2_video',methods =["post"])
def compare1_1st2_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare1_1st2_mihyouka_video',methods =["post"])
def compare1_1st2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/compare1_1st3")
def compare1_1st3():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学１　前期/compare1_1st3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare1_1st3_Review',methods = ["post"])
def compare1_1st3_Review():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare1_1st3_mihyouka_Review", methods=["POST"])
def compare1_1st3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学１　前期/compare1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare1_1st3_video',methods =["post"])
def compare1_1st3_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare1_1st3_mihyouka_video',methods =["post"])
def compare1_1st3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/compare1_1st4")
def compare1_1st4():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学１　前期/compare1_1st4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare1_1st4_Review',methods = ["post"])
def compare1_1st4_Review():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare1_1st4_mihyouka_Review", methods=["POST"])
def compare1_1st4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学１　前期/compare1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare1_1st4_video',methods =["post"])
def compare1_1st4_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare1_1st4_mihyouka_video',methods =["post"])
def compare1_1st4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/compare1_1st5")
def compare1_1st5():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学１　前期/compare1_1st5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare1_1st5_Review',methods = ["post"])
def compare1_1st5_Review():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare1_1st5_mihyouka_Review", methods=["POST"])
def compare1_1st5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学１　前期/compare1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare1_1st5_video',methods =["post"])
def compare1_1st5_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare1_1st5_mihyouka_video',methods =["post"])
def compare1_1st5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/compare1_1st6")
def compare1_1st6():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学１　前期/compare1_1st6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare1_1st6_Review',methods = ["post"])
def compare1_1st6_Review():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare1_1st6_mihyouka_Review", methods=["POST"])
def compare1_1st6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学１　前期/compare1_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare1_1st6_video',methods =["post"])
def compare1_1st6_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare1_1st6_mihyouka_video',methods =["post"])
def compare1_1st6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/compare1_1st7")
def compare1_1st7():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学１　前期/compare1_1st7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare1_1st7_Review',methods = ["post"])
def compare1_1st7_Review():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare1_1st7_mihyouka_Review", methods=["POST"])
def compare1_1st7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学１　前期/compare1_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare1_1st7_video',methods =["post"])
def compare1_1st7_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare1_1st7_mihyouka_video',methods =["post"])
def compare1_1st7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/compare1_1st8")
def compare1_1st8():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学１　前期/compare1_1st8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare1_1st8_Review',methods = ["post"])
def compare1_1st8_Review():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare1_1st8_mihyouka_Review", methods=["POST"])
def compare1_1st8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学１　前期/compare1_1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare1_1st8_video',methods =["post"])
def compare1_1st8_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare1_1st8_mihyouka_video',methods =["post"])
def compare1_1st8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/compare1_1st9")
def compare1_1st9():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学１　前期/compare1_1st9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare1_1st9_Review',methods = ["post"])
def compare1_1st9_Review():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare1_1st9_mihyouka_Review", methods=["POST"])
def compare1_1st9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学１　前期/compare1_1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare1_1st9_video',methods =["post"])
def compare1_1st9_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare1_1st9_mihyouka_video',methods =["post"])
def compare1_1st9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/compare1_1st10")
def compare1_1st10():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学１　前期/compare1_1st10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare1_1st10_Review',methods = ["post"])
def compare1_1st10_Review():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare1_1st10_mihyouka_Review", methods=["POST"])
def compare1_1st10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学１　前期/compare1_1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare1_1st10_video',methods =["post"])
def compare1_1st10_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare1_1st10_mihyouka_video',methods =["post"])
def compare1_1st10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/compare1_1st11")
def compare1_1st11():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学１　前期/compare1_1st11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare1_1st11_Review',methods = ["post"])
def compare1_1st11_Review():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare1_1st11_mihyouka_Review", methods=["POST"])
def compare1_1st11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学１　前期/compare1_1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare1_1st11_video',methods =["post"])
def compare1_1st11_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare1_1st11_mihyouka_video',methods =["post"])
def compare1_1st11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/compare1_1st12")
def compare1_1st12():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学１　前期/compare1_1st12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare1_1st12_Review',methods = ["post"])
def compare1_1st12_Review():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare1_1st12_mihyouka_Review", methods=["POST"])
def compare1_1st12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学１　前期/compare1_1st12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare1_1st12_video',methods =["post"])
def compare1_1st12_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare1_1st12_mihyouka_video',methods =["post"])
def compare1_1st12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/compare1_1st13")
def compare1_1st13():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学１　前期/compare1_1st13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare1_1st13_Review',methods = ["post"])
def compare1_1st13_Review():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare1_1st13_mihyouka_Review", methods=["POST"])
def compare1_1st13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学１　前期/compare1_1st13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare1_1st13_video',methods =["post"])
def compare1_1st13_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare1_1st13_mihyouka_video',methods =["post"])
def compare1_1st13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/compare1_1st14")
def compare1_1st14():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学１　前期/compare1_1st14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare1_1st14_Review',methods = ["post"])
def compare1_1st14_Review():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare1_1st14_mihyouka_Review", methods=["POST"])
def compare1_1st14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学１　前期/compare1_1st14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare1_1st14_video',methods =["post"])
def compare1_1st14_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare1_1st14_mihyouka_video',methods =["post"])
def compare1_1st14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/compare1_1st15")
def compare1_1st15():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学１　前期/compare1_1st15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare1_1st15_Review',methods = ["post"])
def compare1_1st15_Review():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare1_1st15_mihyouka_Review", methods=["POST"])
def compare1_1st15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学１　前期/compare1_1st15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare1_1st15_video',methods =["post"])
def compare1_1st15_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare1_1st15_mihyouka_video',methods =["post"])
def compare1_1st15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学１　前期/比較文化学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学１　前期/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学１　前期/compare1_1st15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################比較文化学２############################
################################################################################################
@app.route("/compare2_")
def compare2_():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/比較文化学２/compare2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/compare2_1")
def compare2_1():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学２/compare2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare2_1_Review',methods = ["post"])
def compare2_1_Review():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare2_1_mihyouka_Review", methods=["POST"])
def compare2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学２/compare2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare2_1_video',methods =["post"])
def compare2_1_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare2_1_mihyouka_video',methods =["post"])
def compare2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/compare2_2")
def compare2_2():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学２/compare2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare2_2_Review',methods = ["post"])
def compare2_2_Review():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare2_2_mihyouka_Review", methods=["POST"])
def compare2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学２/compare2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare2_2_video',methods =["post"])
def compare2_2_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare2_2_mihyouka_video',methods =["post"])
def compare2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/compare2_3")
def compare2_3():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学２/compare2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare2_3_Review',methods = ["post"])
def compare2_3_Review():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare2_3_mihyouka_Review", methods=["POST"])
def compare2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学２/compare2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare2_3_video',methods =["post"])
def compare2_3_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare2_3_mihyouka_video',methods =["post"])
def compare2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/compare2_4")
def compare2_4():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学２/compare2_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare2_4_Review',methods = ["post"])
def compare2_4_Review():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare2_4_mihyouka_Review", methods=["POST"])
def compare2_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学２/compare2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare2_4_video',methods =["post"])
def compare2_4_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare2_4_mihyouka_video',methods =["post"])
def compare2_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/compare2_5")
def compare2_5():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学２/compare2_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare2_5_Review',methods = ["post"])
def compare2_5_Review():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare2_5_mihyouka_Review", methods=["POST"])
def compare2_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学２/compare2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare2_5_video',methods =["post"])
def compare2_5_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare2_5_mihyouka_video',methods =["post"])
def compare2_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/compare2_6")
def compare2_6():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学２/compare2_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare2_6_Review',methods = ["post"])
def compare2_6_Review():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare2_6_mihyouka_Review", methods=["POST"])
def compare2_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学２/compare2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare2_6_video',methods =["post"])
def compare2_6_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare2_6_mihyouka_video',methods =["post"])
def compare2_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/compare2_7")
def compare2_7():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学２/compare2_7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare2_7_Review',methods = ["post"])
def compare2_7_Review():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare2_7_mihyouka_Review", methods=["POST"])
def compare2_7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学２/compare2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare2_7_video',methods =["post"])
def compare2_7_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare2_7_mihyouka_video',methods =["post"])
def compare2_7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/compare2_8")
def compare2_8():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学２/compare2_8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare2_8_Review',methods = ["post"])
def compare2_8_Review():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare2_8_mihyouka_Review", methods=["POST"])
def compare2_8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学２/compare2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare2_8_video',methods =["post"])
def compare2_8_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare2_8_mihyouka_video',methods =["post"])
def compare2_8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/compare2_9")
def compare2_9():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学２/compare2_9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare2_9_Review',methods = ["post"])
def compare2_9_Review():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare2_9_mihyouka_Review", methods=["POST"])
def compare2_9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学２/compare2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare2_9_video',methods =["post"])
def compare2_9_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare2_9_mihyouka_video',methods =["post"])
def compare2_9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/compare2_10")
def compare2_10():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学２/compare2_10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare2_10_Review',methods = ["post"])
def compare2_10_Review():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare2_10_mihyouka_Review", methods=["POST"])
def compare2_10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学２/compare2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare2_10_video',methods =["post"])
def compare2_10_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare2_10_mihyouka_video',methods =["post"])
def compare2_10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/compare2_11")
def compare2_11():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学２/compare2_11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare2_11_Review',methods = ["post"])
def compare2_11_Review():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare2_11_mihyouka_Review", methods=["POST"])
def compare2_11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学２/compare2_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare2_11_video',methods =["post"])
def compare2_11_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare2_11_mihyouka_video',methods =["post"])
def compare2_11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/compare2_12")
def compare2_12():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学２/compare2_12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare2_12_Review',methods = ["post"])
def compare2_12_Review():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare2_12_mihyouka_Review", methods=["POST"])
def compare2_12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学２/compare2_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare2_12_video',methods =["post"])
def compare2_12_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare2_12_mihyouka_video',methods =["post"])
def compare2_12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/compare2_13")
def compare2_13():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学２/compare2_13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare2_13_Review',methods = ["post"])
def compare2_13_Review():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare2_13_mihyouka_Review", methods=["POST"])
def compare2_13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学２/compare2_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare2_13_video',methods =["post"])
def compare2_13_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare2_13_mihyouka_video',methods =["post"])
def compare2_13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/compare2_14")
def compare2_14():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学２/compare2_14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare2_14_Review',methods = ["post"])
def compare2_14_Review():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare2_14_mihyouka_Review", methods=["POST"])
def compare2_14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学２/compare2_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare2_14_video',methods =["post"])
def compare2_14_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare2_14_mihyouka_video',methods =["post"])
def compare2_14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/compare2_15")
def compare2_15():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/比較文化学２/compare2_15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/compare2_15_Review',methods = ["post"])
def compare2_15_Review():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/compare2_15_mihyouka_Review", methods=["POST"])
def compare2_15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/比較文化学２/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/比較文化学２/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/比較文化学２/compare2_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/compare2_15_video',methods =["post"])
def compare2_15_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/compare2_15_mihyouka_video',methods =["post"])
def compare2_15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/比較文化学２/比較文化学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/比較文化学２/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/比較文化学２/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/比較文化学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/比較文化学２/compare2_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################微分方程式論############################
################################################################################################
@app.route("/diff_equ")
def diff_equ():
    df_key = pd.read_csv("Kamoku/微分方程式論/微分方程式論.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/微分方程式論/diff_equ_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/diff_equ1")
def diff_equ1():
    df_key = pd.read_csv("Kamoku/微分方程式論/微分方程式論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/微分方程式論/diff_equ1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/diff_equ1_Review',methods = ["post"])
def diff_equ1_Review():
    df_key = pd.read_csv("Kamoku/微分方程式論/微分方程式論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/微分方程式論/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/微分方程式論/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/微分方程式論/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/微分方程式論/diff_equ1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/diff_equ1_mihyouka_Review", methods=["POST"])
def diff_equ1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/微分方程式論/微分方程式論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/微分方程式論/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/微分方程式論/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/微分方程式論/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/微分方程式論/diff_equ1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/diff_equ1_video',methods =["post"])
def diff_equ1_video():
    df_key = pd.read_csv("Kamoku/微分方程式論/微分方程式論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/微分方程式論/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/微分方程式論/diff_equ1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/diff_equ1_mihyouka_video',methods =["post"])
def diff_equ1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/微分方程式論/微分方程式論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/微分方程式論/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/微分方程式論/diff_equ1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/diff_equ2")
def diff_equ2():
    df_key = pd.read_csv("Kamoku/微分方程式論/微分方程式論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/微分方程式論/diff_equ2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/diff_equ2_Review',methods = ["post"])
def diff_equ2_Review():
    df_key = pd.read_csv("Kamoku/微分方程式論/微分方程式論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/微分方程式論/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/微分方程式論/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/微分方程式論/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/微分方程式論/diff_equ2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/diff_equ2_mihyouka_Review", methods=["POST"])
def diff_equ2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/微分方程式論/微分方程式論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/微分方程式論/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/微分方程式論/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/微分方程式論/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/微分方程式論/diff_equ2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/diff_equ2_video',methods =["post"])
def diff_equ2_video():
    df_key = pd.read_csv("Kamoku/微分方程式論/微分方程式論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/微分方程式論/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/微分方程式論/diff_equ2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/diff_equ2_mihyouka_video',methods =["post"])
def diff_equ2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/微分方程式論/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/微分方程式論/diff_equ2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/diff_equ3")
def diff_equ3():
    df_key = pd.read_csv("Kamoku/微分方程式論/微分方程式論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/微分方程式論/diff_equ3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/diff_equ3_Review',methods = ["post"])
def diff_equ3_Review():
    df_key = pd.read_csv("Kamoku/微分方程式論/微分方程式論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/微分方程式論/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/微分方程式論/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/微分方程式論/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/微分方程式論/diff_equ3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/diff_equ3_mihyouka_Review", methods=["POST"])
def diff_equ3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/微分方程式論/微分方程式論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/微分方程式論/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/微分方程式論/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/微分方程式論/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/微分方程式論/diff_equ3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/diff_equ3_video',methods =["post"])
def diff_equ3_video():
    df_key = pd.read_csv("Kamoku/微分方程式論/微分方程式論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/微分方程式論/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/微分方程式論/diff_equ3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/diff_equ3_mihyouka_video',methods =["post"])
def diff_equ3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/微分方程式論/微分方程式論.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/微分方程式論/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/微分方程式論/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/微分方程式論/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/微分方程式論/diff_equ3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################富山と日本海############################
################################################################################################
@app.route("/toyama_japan")
def toyama_japan():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/富山と日本海/toyama_japan_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/toyama_japan1")
def toyama_japan1():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/富山と日本海/toyama_japan1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/toyama_japan1_Review',methods = ["post"])
def toyama_japan1_Review():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/toyama_japan1_mihyouka_Review", methods=["POST"])
def toyama_japan1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/富山と日本海/toyama_japan1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/toyama_japan1_video',methods =["post"])
def toyama_japan1_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/toyama_japan1_mihyouka_video',methods =["post"])
def toyama_japan1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/toyama_japan2")
def toyama_japan2():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/富山と日本海/toyama_japan2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/toyama_japan2_Review',methods = ["post"])
def toyama_japan2_Review():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/toyama_japan2_mihyouka_Review", methods=["POST"])
def toyama_japan2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/富山と日本海/toyama_japan2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/toyama_japan2_video',methods =["post"])
def toyama_japan2_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/toyama_japan2_mihyouka_video',methods =["post"])
def toyama_japan2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/toyama_japan3")
def toyama_japan3():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/富山と日本海/toyama_japan3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/toyama_japan3_Review',methods = ["post"])
def toyama_japan3_Review():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/toyama_japan3_mihyouka_Review", methods=["POST"])
def toyama_japan3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/富山と日本海/toyama_japan3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/toyama_japan3_video',methods =["post"])
def toyama_japan3_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/toyama_japan3_mihyouka_video',methods =["post"])
def toyama_japan3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/toyama_japan4")
def toyama_japan4():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/富山と日本海/toyama_japan4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/toyama_japan4_Review',methods = ["post"])
def toyama_japan4_Review():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/toyama_japan4_mihyouka_Review", methods=["POST"])
def toyama_japan4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/富山と日本海/toyama_japan4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/toyama_japan4_video',methods =["post"])
def toyama_japan4_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/toyama_japan4_mihyouka_video',methods =["post"])
def toyama_japan4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/toyama_japan5")
def toyama_japan5():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/富山と日本海/toyama_japan5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/toyama_japan5_Review',methods = ["post"])
def toyama_japan5_Review():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/toyama_japan5_mihyouka_Review", methods=["POST"])
def toyama_japan5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/富山と日本海/toyama_japan5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/toyama_japan5_video',methods =["post"])
def toyama_japan5_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/toyama_japan5_mihyouka_video',methods =["post"])
def toyama_japan5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/toyama_japan6")
def toyama_japan6():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/富山と日本海/toyama_japan6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/toyama_japan6_Review',methods = ["post"])
def toyama_japan6_Review():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/toyama_japan6_mihyouka_Review", methods=["POST"])
def toyama_japan6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/富山と日本海/toyama_japan6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/toyama_japan6_video',methods =["post"])
def toyama_japan6_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/toyama_japan6_mihyouka_video',methods =["post"])
def toyama_japan6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/toyama_japan7")
def toyama_japan7():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/富山と日本海/toyama_japan7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/toyama_japan7_Review',methods = ["post"])
def toyama_japan7_Review():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/toyama_japan7_mihyouka_Review", methods=["POST"])
def toyama_japan7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/富山と日本海/toyama_japan7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/toyama_japan7_video',methods =["post"])
def toyama_japan7_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/toyama_japan7_mihyouka_video',methods =["post"])
def toyama_japan7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/toyama_japan8")
def toyama_japan8():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/富山と日本海/toyama_japan8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/toyama_japan8_Review',methods = ["post"])
def toyama_japan8_Review():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/toyama_japan8_mihyouka_Review", methods=["POST"])
def toyama_japan8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/富山と日本海/toyama_japan8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/toyama_japan8_video',methods =["post"])
def toyama_japan8_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/toyama_japan8_mihyouka_video',methods =["post"])
def toyama_japan8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/toyama_japan9")
def toyama_japan9():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/富山と日本海/toyama_japan9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/toyama_japan9_Review',methods = ["post"])
def toyama_japan9_Review():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/toyama_japan9_mihyouka_Review", methods=["POST"])
def toyama_japan9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/富山と日本海/toyama_japan9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/toyama_japan9_video',methods =["post"])
def toyama_japan9_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/toyama_japan9_mihyouka_video',methods =["post"])
def toyama_japan9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/toyama_japan10")
def toyama_japan10():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/富山と日本海/toyama_japan10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/toyama_japan10_Review',methods = ["post"])
def toyama_japan10_Review():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/toyama_japan10_mihyouka_Review", methods=["POST"])
def toyama_japan10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/富山と日本海/toyama_japan10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/toyama_japan10_video',methods =["post"])
def toyama_japan10_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/toyama_japan10_mihyouka_video',methods =["post"])
def toyama_japan10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/toyama_japan11")
def toyama_japan11():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/富山と日本海/toyama_japan11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/toyama_japan11_Review',methods = ["post"])
def toyama_japan11_Review():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/toyama_japan11_mihyouka_Review", methods=["POST"])
def toyama_japan11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/富山と日本海/toyama_japan11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/toyama_japan11_video',methods =["post"])
def toyama_japan11_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/toyama_japan11_mihyouka_video',methods =["post"])
def toyama_japan11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/toyama_japan12")
def toyama_japan12():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/富山と日本海/toyama_japan12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/toyama_japan12_Review',methods = ["post"])
def toyama_japan12_Review():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/toyama_japan12_mihyouka_Review", methods=["POST"])
def toyama_japan12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/富山と日本海/toyama_japan12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/toyama_japan12_video',methods =["post"])
def toyama_japan12_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/toyama_japan12_mihyouka_video',methods =["post"])
def toyama_japan12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/toyama_japan13")
def toyama_japan13():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/富山と日本海/toyama_japan13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/toyama_japan13_Review',methods = ["post"])
def toyama_japan13_Review():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/toyama_japan13_mihyouka_Review", methods=["POST"])
def toyama_japan13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/富山と日本海/toyama_japan13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/toyama_japan13_video',methods =["post"])
def toyama_japan13_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/toyama_japan13_mihyouka_video',methods =["post"])
def toyama_japan13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/toyama_japan14")
def toyama_japan14():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/富山と日本海/toyama_japan14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/toyama_japan14_Review',methods = ["post"])
def toyama_japan14_Review():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/toyama_japan14_mihyouka_Review", methods=["POST"])
def toyama_japan14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/富山と日本海/toyama_japan14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/toyama_japan14_video',methods =["post"])
def toyama_japan14_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/toyama_japan14_mihyouka_video',methods =["post"])
def toyama_japan14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/toyama_japan15")
def toyama_japan15():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/富山と日本海/toyama_japan15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/toyama_japan15_Review',methods = ["post"])
def toyama_japan15_Review():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/toyama_japan15_mihyouka_Review", methods=["POST"])
def toyama_japan15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/富山と日本海/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/富山と日本海/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/富山と日本海/toyama_japan15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/toyama_japan15_video',methods =["post"])
def toyama_japan15_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/toyama_japan15_mihyouka_video',methods =["post"])
def toyama_japan15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/富山と日本海/富山と日本海.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/富山と日本海/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/富山と日本海/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/富山と日本海/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/富山と日本海/toyama_japan15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################複素解析学############################
################################################################################################
@app.route("/complex_ana")
def complex_ana():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/複素解析学/complex_ana_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/complex_ana1")
def complex_ana1():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/複素解析学/complex_ana1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/complex_ana1_Review',methods = ["post"])
def complex_ana1_Review():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/複素解析学/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/complex_ana1_mihyouka_Review", methods=["POST"])
def complex_ana1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/複素解析学/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/複素解析学/complex_ana1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/complex_ana1_video',methods =["post"])
def complex_ana1_video():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/複素解析学/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/複素解析学/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/複素解析学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/complex_ana1_mihyouka_video',methods =["post"])
def complex_ana1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/複素解析学/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/複素解析学/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/複素解析学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/complex_ana2")
def complex_ana2():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/複素解析学/complex_ana2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/complex_ana2_Review',methods = ["post"])
def complex_ana2_Review():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/複素解析学/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/complex_ana2_mihyouka_Review", methods=["POST"])
def complex_ana2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/複素解析学/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/複素解析学/complex_ana2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/complex_ana2_video',methods =["post"])
def complex_ana2_video():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/複素解析学/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/複素解析学/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/複素解析学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/complex_ana2_mihyouka_video',methods =["post"])
def complex_ana2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/複素解析学/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/複素解析学/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/複素解析学/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/complex_ana3")
def complex_ana3():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/複素解析学/complex_ana3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/complex_ana3_Review',methods = ["post"])
def complex_ana3_Review():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/複素解析学/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/complex_ana3_mihyouka_Review", methods=["POST"])
def complex_ana3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/複素解析学/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/複素解析学/complex_ana3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/complex_ana3_video',methods =["post"])
def complex_ana3_video():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/複素解析学/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/複素解析学/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/複素解析学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/complex_ana3_mihyouka_video',methods =["post"])
def complex_ana3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/複素解析学/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/複素解析学/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/複素解析学/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/complex_ana4")
def complex_ana4():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/複素解析学/complex_ana4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/complex_ana4_Review',methods = ["post"])
def complex_ana4_Review():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/複素解析学/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/complex_ana4_mihyouka_Review", methods=["POST"])
def complex_ana4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/複素解析学/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/複素解析学/complex_ana4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/complex_ana4_video',methods =["post"])
def complex_ana4_video():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/複素解析学/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/複素解析学/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/複素解析学/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/complex_ana4_mihyouka_video',methods =["post"])
def complex_ana4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/複素解析学/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/複素解析学/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/複素解析学/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/complex_ana5")
def complex_ana5():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/複素解析学/complex_ana5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/complex_ana5_Review',methods = ["post"])
def complex_ana5_Review():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/複素解析学/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/complex_ana5_mihyouka_Review", methods=["POST"])
def complex_ana5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/複素解析学/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/複素解析学/complex_ana5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/complex_ana5_video',methods =["post"])
def complex_ana5_video():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/複素解析学/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/複素解析学/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/複素解析学/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/complex_ana5_mihyouka_video',methods =["post"])
def complex_ana5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/複素解析学/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/複素解析学/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/複素解析学/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/complex_ana6")
def complex_ana6():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/複素解析学/complex_ana6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/complex_ana6_Review',methods = ["post"])
def complex_ana6_Review():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/複素解析学/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/complex_ana6_mihyouka_Review", methods=["POST"])
def complex_ana6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/複素解析学/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/複素解析学/complex_ana6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/complex_ana6_video',methods =["post"])
def complex_ana6_video():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/複素解析学/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/複素解析学/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/複素解析学/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/complex_ana6_mihyouka_video',methods =["post"])
def complex_ana6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/複素解析学/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/複素解析学/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/複素解析学/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/complex_ana7")
def complex_ana7():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/複素解析学/complex_ana7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/complex_ana7_Review',methods = ["post"])
def complex_ana7_Review():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/複素解析学/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/complex_ana7_mihyouka_Review", methods=["POST"])
def complex_ana7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/複素解析学/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/複素解析学/complex_ana7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/complex_ana7_video',methods =["post"])
def complex_ana7_video():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/複素解析学/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/複素解析学/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/複素解析学/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/complex_ana7_mihyouka_video',methods =["post"])
def complex_ana7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/複素解析学/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/複素解析学/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/複素解析学/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/complex_ana8")
def complex_ana8():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/複素解析学/complex_ana8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/complex_ana8_Review',methods = ["post"])
def complex_ana8_Review():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/複素解析学/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/complex_ana8_mihyouka_Review", methods=["POST"])
def complex_ana8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/複素解析学/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/複素解析学/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/複素解析学/complex_ana8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/complex_ana8_video',methods =["post"])
def complex_ana8_video():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/複素解析学/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/複素解析学/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/複素解析学/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/complex_ana8_mihyouka_video',methods =["post"])
def complex_ana8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/複素解析学/複素解析学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/複素解析学/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/複素解析学/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/複素解析学/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/複素解析学/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/複素解析学/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/複素解析学/complex_ana8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################物理学１############################
################################################################################################
@app.route("/physic1_")
def physic1_():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/物理学１/physic1__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/physic1_1")
def physic1_1():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１/physic1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_1_Review',methods = ["post"])
def physic1_1_Review():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_1_mihyouka_Review", methods=["POST"])
def physic1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１/physic1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_1_video',methods =["post"])
def physic1_1_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_1_mihyouka_video',methods =["post"])
def physic1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/physic1_2")
def physic1_2():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１/physic1_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_2_Review',methods = ["post"])
def physic1_2_Review():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_2_mihyouka_Review", methods=["POST"])
def physic1_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１/physic1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_2_video',methods =["post"])
def physic1_2_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_2_mihyouka_video',methods =["post"])
def physic1_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/physic1_3")
def physic1_3():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１/physic1_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_3_Review',methods = ["post"])
def physic1_3_Review():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_3_mihyouka_Review", methods=["POST"])
def physic1_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１/physic1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_3_video',methods =["post"])
def physic1_3_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_3_mihyouka_video',methods =["post"])
def physic1_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/physic1_4")
def physic1_4():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１/physic1_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_4_Review',methods = ["post"])
def physic1_4_Review():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_4_mihyouka_Review", methods=["POST"])
def physic1_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１/physic1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_4_video',methods =["post"])
def physic1_4_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_4_mihyouka_video',methods =["post"])
def physic1_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/physic1_5")
def physic1_5():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１/physic1_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_5_Review',methods = ["post"])
def physic1_5_Review():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_5_mihyouka_Review", methods=["POST"])
def physic1_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１/physic1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_5_video',methods =["post"])
def physic1_5_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_5_mihyouka_video',methods =["post"])
def physic1_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/physic1_6")
def physic1_6():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１/physic1_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_6_Review',methods = ["post"])
def physic1_6_Review():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_6_mihyouka_Review", methods=["POST"])
def physic1_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１/physic1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_6_video',methods =["post"])
def physic1_6_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_6_mihyouka_video',methods =["post"])
def physic1_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/physic1_7")
def physic1_7():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１/physic1_7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_7_Review',methods = ["post"])
def physic1_7_Review():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_7_mihyouka_Review", methods=["POST"])
def physic1_7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１/physic1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_7_video',methods =["post"])
def physic1_7_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_7_mihyouka_video',methods =["post"])
def physic1_7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/physic1_8")
def physic1_8():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１/physic1_8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_8_Review',methods = ["post"])
def physic1_8_Review():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_8_mihyouka_Review", methods=["POST"])
def physic1_8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１/physic1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_8_video',methods =["post"])
def physic1_8_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_8_mihyouka_video',methods =["post"])
def physic1_8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/physic1_9")
def physic1_9():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１/physic1_9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_9_Review',methods = ["post"])
def physic1_9_Review():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_9_mihyouka_Review", methods=["POST"])
def physic1_9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１/physic1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_9_video',methods =["post"])
def physic1_9_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_9_mihyouka_video',methods =["post"])
def physic1_9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/physic1_10")
def physic1_10():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１/physic1_10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_10_Review',methods = ["post"])
def physic1_10_Review():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_10_mihyouka_Review", methods=["POST"])
def physic1_10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１/physic1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_10_video',methods =["post"])
def physic1_10_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_10_mihyouka_video',methods =["post"])
def physic1_10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/physic1_11")
def physic1_11():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１/physic1_11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_11_Review',methods = ["post"])
def physic1_11_Review():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_11_mihyouka_Review", methods=["POST"])
def physic1_11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１/physic1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_11_video',methods =["post"])
def physic1_11_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_11_mihyouka_video',methods =["post"])
def physic1_11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/physic1_12")
def physic1_12():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１/physic1_12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_12_Review',methods = ["post"])
def physic1_12_Review():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_12_mihyouka_Review", methods=["POST"])
def physic1_12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１/physic1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_12_video',methods =["post"])
def physic1_12_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_12_mihyouka_video',methods =["post"])
def physic1_12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/physic1_13")
def physic1_13():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１/physic1_13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_13_Review',methods = ["post"])
def physic1_13_Review():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_13_mihyouka_Review", methods=["POST"])
def physic1_13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１/physic1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_13_video',methods =["post"])
def physic1_13_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_13_mihyouka_video',methods =["post"])
def physic1_13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/physic1_14")
def physic1_14():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１/physic1_14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_14_Review',methods = ["post"])
def physic1_14_Review():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_14_mihyouka_Review", methods=["POST"])
def physic1_14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１/physic1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_14_video',methods =["post"])
def physic1_14_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_14_mihyouka_video',methods =["post"])
def physic1_14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/physic1_15")
def physic1_15():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１/physic1_15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_15_Review',methods = ["post"])
def physic1_15_Review():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_15_mihyouka_Review", methods=["POST"])
def physic1_15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１/physic1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_15_video',methods =["post"])
def physic1_15_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_15_mihyouka_video',methods =["post"])
def physic1_15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１/物理学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１/physic1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################物理学１演習############################
################################################################################################
@app.route("/physic1_exe")
def physic1_exe():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/物理学１演習/physic1_exe_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/physic1_exe1")
def physic1_exe1():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１演習/physic1_exe1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_exe1_Review',methods = ["post"])
def physic1_exe1_Review():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_exe1_mihyouka_Review", methods=["POST"])
def physic1_exe1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１演習/physic1_exe1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_exe1_video',methods =["post"])
def physic1_exe1_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_exe1_mihyouka_video',methods =["post"])
def physic1_exe1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/physic1_exe2")
def physic1_exe2():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１演習/physic1_exe2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_exe2_Review',methods = ["post"])
def physic1_exe2_Review():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_exe2_mihyouka_Review", methods=["POST"])
def physic1_exe2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１演習/physic1_exe2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_exe2_video',methods =["post"])
def physic1_exe2_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_exe2_mihyouka_video',methods =["post"])
def physic1_exe2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/physic1_exe3")
def physic1_exe3():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１演習/physic1_exe3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_exe3_Review',methods = ["post"])
def physic1_exe3_Review():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_exe3_mihyouka_Review", methods=["POST"])
def physic1_exe3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１演習/physic1_exe3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_exe3_video',methods =["post"])
def physic1_exe3_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_exe3_mihyouka_video',methods =["post"])
def physic1_exe3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/physic1_exe4")
def physic1_exe4():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１演習/physic1_exe4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_exe4_Review',methods = ["post"])
def physic1_exe4_Review():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_exe4_mihyouka_Review", methods=["POST"])
def physic1_exe4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１演習/physic1_exe4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_exe4_video',methods =["post"])
def physic1_exe4_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_exe4_mihyouka_video',methods =["post"])
def physic1_exe4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/physic1_exe5")
def physic1_exe5():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１演習/physic1_exe5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_exe5_Review',methods = ["post"])
def physic1_exe5_Review():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_exe5_mihyouka_Review", methods=["POST"])
def physic1_exe5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１演習/physic1_exe5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_exe5_video',methods =["post"])
def physic1_exe5_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_exe5_mihyouka_video',methods =["post"])
def physic1_exe5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/physic1_exe6")
def physic1_exe6():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１演習/physic1_exe6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_exe6_Review',methods = ["post"])
def physic1_exe6_Review():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_exe6_mihyouka_Review", methods=["POST"])
def physic1_exe6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１演習/physic1_exe6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_exe6_video',methods =["post"])
def physic1_exe6_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_exe6_mihyouka_video',methods =["post"])
def physic1_exe6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/physic1_exe7")
def physic1_exe7():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１演習/physic1_exe7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_exe7_Review',methods = ["post"])
def physic1_exe7_Review():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_exe7_mihyouka_Review", methods=["POST"])
def physic1_exe7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１演習/physic1_exe7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_exe7_video',methods =["post"])
def physic1_exe7_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_exe7_mihyouka_video',methods =["post"])
def physic1_exe7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/physic1_exe8")
def physic1_exe8():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１演習/physic1_exe8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_exe8_Review',methods = ["post"])
def physic1_exe8_Review():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_exe8_mihyouka_Review", methods=["POST"])
def physic1_exe8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１演習/physic1_exe8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_exe8_video',methods =["post"])
def physic1_exe8_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_exe8_mihyouka_video',methods =["post"])
def physic1_exe8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/physic1_exe9")
def physic1_exe9():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１演習/physic1_exe9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_exe9_Review',methods = ["post"])
def physic1_exe9_Review():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_exe9_mihyouka_Review", methods=["POST"])
def physic1_exe9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１演習/physic1_exe9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_exe9_video',methods =["post"])
def physic1_exe9_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_exe9_mihyouka_video',methods =["post"])
def physic1_exe9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/physic1_exe10")
def physic1_exe10():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１演習/physic1_exe10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_exe10_Review',methods = ["post"])
def physic1_exe10_Review():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_exe10_mihyouka_Review", methods=["POST"])
def physic1_exe10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１演習/physic1_exe10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_exe10_video',methods =["post"])
def physic1_exe10_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_exe10_mihyouka_video',methods =["post"])
def physic1_exe10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/physic1_exe11")
def physic1_exe11():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１演習/physic1_exe11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_exe11_Review',methods = ["post"])
def physic1_exe11_Review():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_exe11_mihyouka_Review", methods=["POST"])
def physic1_exe11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１演習/physic1_exe11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_exe11_video',methods =["post"])
def physic1_exe11_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_exe11_mihyouka_video',methods =["post"])
def physic1_exe11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/physic1_exe12")
def physic1_exe12():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１演習/physic1_exe12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_exe12_Review',methods = ["post"])
def physic1_exe12_Review():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_exe12_mihyouka_Review", methods=["POST"])
def physic1_exe12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１演習/physic1_exe12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_exe12_video',methods =["post"])
def physic1_exe12_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_exe12_mihyouka_video',methods =["post"])
def physic1_exe12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/physic1_exe13")
def physic1_exe13():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１演習/physic1_exe13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_exe13_Review',methods = ["post"])
def physic1_exe13_Review():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_exe13_mihyouka_Review", methods=["POST"])
def physic1_exe13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１演習/physic1_exe13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_exe13_video',methods =["post"])
def physic1_exe13_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_exe13_mihyouka_video',methods =["post"])
def physic1_exe13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/physic1_exe14")
def physic1_exe14():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１演習/physic1_exe14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_exe14_Review',methods = ["post"])
def physic1_exe14_Review():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_exe14_mihyouka_Review", methods=["POST"])
def physic1_exe14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１演習/physic1_exe14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_exe14_video',methods =["post"])
def physic1_exe14_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_exe14_mihyouka_video',methods =["post"])
def physic1_exe14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/physic1_exe15")
def physic1_exe15():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学１演習/physic1_exe15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic1_exe15_Review',methods = ["post"])
def physic1_exe15_Review():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic1_exe15_mihyouka_Review", methods=["POST"])
def physic1_exe15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学１演習/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学１演習/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学１演習/physic1_exe15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic1_exe15_video',methods =["post"])
def physic1_exe15_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic1_exe15_mihyouka_video',methods =["post"])
def physic1_exe15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学１演習/物理学１演習.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学１演習/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学１演習/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学１演習/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学１演習/physic1_exe15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################物理学２############################
################################################################################################
@app.route("/physic2_")
def physic2_():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/物理学２/physic2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/physic2_1")
def physic2_1():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学２/physic2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic2_1_Review',methods = ["post"])
def physic2_1_Review():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic2_1_mihyouka_Review", methods=["POST"])
def physic2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学２/physic2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic2_1_video',methods =["post"])
def physic2_1_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic2_1_mihyouka_video',methods =["post"])
def physic2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/physic2_2")
def physic2_2():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学２/physic2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic2_2_Review',methods = ["post"])
def physic2_2_Review():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic2_2_mihyouka_Review", methods=["POST"])
def physic2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学２/physic2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic2_2_video',methods =["post"])
def physic2_2_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic2_2_mihyouka_video',methods =["post"])
def physic2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/physic2_3")
def physic2_3():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学２/physic2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic2_3_Review',methods = ["post"])
def physic2_3_Review():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic2_3_mihyouka_Review", methods=["POST"])
def physic2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学２/physic2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic2_3_video',methods =["post"])
def physic2_3_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic2_3_mihyouka_video',methods =["post"])
def physic2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/physic2_4")
def physic2_4():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学２/physic2_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic2_4_Review',methods = ["post"])
def physic2_4_Review():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic2_4_mihyouka_Review", methods=["POST"])
def physic2_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学２/physic2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic2_4_video',methods =["post"])
def physic2_4_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic2_4_mihyouka_video',methods =["post"])
def physic2_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/physic2_5")
def physic2_5():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学２/physic2_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic2_5_Review',methods = ["post"])
def physic2_5_Review():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic2_5_mihyouka_Review", methods=["POST"])
def physic2_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学２/physic2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic2_5_video',methods =["post"])
def physic2_5_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学２/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic2_5_mihyouka_video',methods =["post"])
def physic2_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学２/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/physic2_6")
def physic2_6():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学２/physic2_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic2_6_Review',methods = ["post"])
def physic2_6_Review():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic2_6_mihyouka_Review", methods=["POST"])
def physic2_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学２/physic2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic2_6_video',methods =["post"])
def physic2_6_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学２/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic2_6_mihyouka_video',methods =["post"])
def physic2_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学２/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/physic2_7")
def physic2_7():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学２/physic2_7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic2_7_Review',methods = ["post"])
def physic2_7_Review():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic2_7_mihyouka_Review", methods=["POST"])
def physic2_7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学２/physic2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic2_7_video',methods =["post"])
def physic2_7_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学２/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic2_7_mihyouka_video',methods =["post"])
def physic2_7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学２/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/physic2_8")
def physic2_8():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学２/physic2_8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic2_8_Review',methods = ["post"])
def physic2_8_Review():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic2_8_mihyouka_Review", methods=["POST"])
def physic2_8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学２/physic2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic2_8_video',methods =["post"])
def physic2_8_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学２/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic2_8_mihyouka_video',methods =["post"])
def physic2_8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学２/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/physic2_9")
def physic2_9():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学２/physic2_9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic2_9_Review',methods = ["post"])
def physic2_9_Review():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic2_9_mihyouka_Review", methods=["POST"])
def physic2_9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学２/physic2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic2_9_video',methods =["post"])
def physic2_9_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学２/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic2_9_mihyouka_video',methods =["post"])
def physic2_9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学２/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/physic2_10")
def physic2_10():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学２/physic2_10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic2_10_Review',methods = ["post"])
def physic2_10_Review():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic2_10_mihyouka_Review", methods=["POST"])
def physic2_10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学２/physic2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic2_10_video',methods =["post"])
def physic2_10_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学２/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic2_10_mihyouka_video',methods =["post"])
def physic2_10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学２/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/physic2_11")
def physic2_11():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学２/physic2_11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic2_11_Review',methods = ["post"])
def physic2_11_Review():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic2_11_mihyouka_Review", methods=["POST"])
def physic2_11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学２/physic2_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic2_11_video',methods =["post"])
def physic2_11_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学２/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic2_11_mihyouka_video',methods =["post"])
def physic2_11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学２/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/physic2_12")
def physic2_12():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学２/physic2_12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic2_12_Review',methods = ["post"])
def physic2_12_Review():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic2_12_mihyouka_Review", methods=["POST"])
def physic2_12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学２/physic2_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic2_12_video',methods =["post"])
def physic2_12_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学２/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic2_12_mihyouka_video',methods =["post"])
def physic2_12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学２/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/physic2_13")
def physic2_13():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学２/physic2_13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic2_13_Review',methods = ["post"])
def physic2_13_Review():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic2_13_mihyouka_Review", methods=["POST"])
def physic2_13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学２/physic2_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic2_13_video',methods =["post"])
def physic2_13_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学２/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic2_13_mihyouka_video',methods =["post"])
def physic2_13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学２/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/physic2_14")
def physic2_14():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学２/physic2_14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic2_14_Review',methods = ["post"])
def physic2_14_Review():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic2_14_mihyouka_Review", methods=["POST"])
def physic2_14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学２/physic2_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic2_14_video',methods =["post"])
def physic2_14_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学２/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic2_14_mihyouka_video',methods =["post"])
def physic2_14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学２/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/physic2_15")
def physic2_15():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理学２/physic2_15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic2_15_Review',methods = ["post"])
def physic2_15_Review():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic2_15_mihyouka_Review", methods=["POST"])
def physic2_15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理学２/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理学２/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理学２/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理学２/physic2_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic2_15_video',methods =["post"])
def physic2_15_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理学２/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic2_15_mihyouka_video',methods =["post"])
def physic2_15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理学２/物理学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理学２/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理学２/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理学２/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理学２/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理学２/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理学２/physic2_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################物理実験　後############################
################################################################################################
@app.route("/physic_exp2st")
def physic_exp2st():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/物理実験　後/physic_exp2st_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/physic_exp2st1")
def physic_exp2st1():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　後/physic_exp2st1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp2st1_Review',methods = ["post"])
def physic_exp2st1_Review():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp2st1_mihyouka_Review", methods=["POST"])
def physic_exp2st1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　後/physic_exp2st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp2st1_video',methods =["post"])
def physic_exp2st1_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp2st1_mihyouka_video',methods =["post"])
def physic_exp2st1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/physic_exp2st2")
def physic_exp2st2():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　後/physic_exp2st2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp2st2_Review',methods = ["post"])
def physic_exp2st2_Review():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp2st2_mihyouka_Review", methods=["POST"])
def physic_exp2st2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　後/physic_exp2st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp2st2_video',methods =["post"])
def physic_exp2st2_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp2st2_mihyouka_video',methods =["post"])
def physic_exp2st2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/physic_exp2st3")
def physic_exp2st3():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　後/physic_exp2st3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp2st3_Review',methods = ["post"])
def physic_exp2st3_Review():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp2st3_mihyouka_Review", methods=["POST"])
def physic_exp2st3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　後/physic_exp2st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp2st3_video',methods =["post"])
def physic_exp2st3_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp2st3_mihyouka_video',methods =["post"])
def physic_exp2st3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/physic_exp2st4")
def physic_exp2st4():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　後/physic_exp2st4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp2st4_Review',methods = ["post"])
def physic_exp2st4_Review():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp2st4_mihyouka_Review", methods=["POST"])
def physic_exp2st4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　後/physic_exp2st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp2st4_video',methods =["post"])
def physic_exp2st4_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp2st4_mihyouka_video',methods =["post"])
def physic_exp2st4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/physic_exp2st5")
def physic_exp2st5():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　後/physic_exp2st5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp2st5_Review',methods = ["post"])
def physic_exp2st5_Review():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp2st5_mihyouka_Review", methods=["POST"])
def physic_exp2st5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　後/physic_exp2st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp2st5_video',methods =["post"])
def physic_exp2st5_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp2st5_mihyouka_video',methods =["post"])
def physic_exp2st5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/physic_exp2st6")
def physic_exp2st6():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　後/physic_exp2st6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp2st6_Review',methods = ["post"])
def physic_exp2st6_Review():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp2st6_mihyouka_Review", methods=["POST"])
def physic_exp2st6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　後/physic_exp2st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp2st6_video',methods =["post"])
def physic_exp2st6_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp2st6_mihyouka_video',methods =["post"])
def physic_exp2st6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/physic_exp2st7")
def physic_exp2st7():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　後/physic_exp2st7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp2st7_Review',methods = ["post"])
def physic_exp2st7_Review():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp2st7_mihyouka_Review", methods=["POST"])
def physic_exp2st7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　後/physic_exp2st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp2st7_video',methods =["post"])
def physic_exp2st7_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp2st7_mihyouka_video',methods =["post"])
def physic_exp2st7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/physic_exp2st8")
def physic_exp2st8():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　後/physic_exp2st8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp2st8_Review',methods = ["post"])
def physic_exp2st8_Review():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp2st8_mihyouka_Review", methods=["POST"])
def physic_exp2st8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　後/physic_exp2st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp2st8_video',methods =["post"])
def physic_exp2st8_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp2st8_mihyouka_video',methods =["post"])
def physic_exp2st8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/physic_exp2st9")
def physic_exp2st9():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　後/physic_exp2st9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp2st9_Review',methods = ["post"])
def physic_exp2st9_Review():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp2st9_mihyouka_Review", methods=["POST"])
def physic_exp2st9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　後/physic_exp2st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp2st9_video',methods =["post"])
def physic_exp2st9_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp2st9_mihyouka_video',methods =["post"])
def physic_exp2st9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/physic_exp2st10")
def physic_exp2st10():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　後/physic_exp2st10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp2st10_Review',methods = ["post"])
def physic_exp2st10_Review():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp2st10_mihyouka_Review", methods=["POST"])
def physic_exp2st10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　後/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　後/physic_exp2st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp2st10_video',methods =["post"])
def physic_exp2st10_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp2st10_mihyouka_video',methods =["post"])
def physic_exp2st10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　後/物理実験　後.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　後/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　後/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　後/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　後/physic_exp2st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################物理実験　前############################
################################################################################################
@app.route("/physic_exp1st")
def physic_exp1st():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/物理実験　前/physic_exp1st_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/physic_exp1st1")
def physic_exp1st1():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　前/physic_exp1st1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp1st1_Review',methods = ["post"])
def physic_exp1st1_Review():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp1st1_mihyouka_Review", methods=["POST"])
def physic_exp1st1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　前/physic_exp1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp1st1_video',methods =["post"])
def physic_exp1st1_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp1st1_mihyouka_video',methods =["post"])
def physic_exp1st1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/physic_exp1st2")
def physic_exp1st2():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　前/physic_exp1st2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp1st2_Review',methods = ["post"])
def physic_exp1st2_Review():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp1st2_mihyouka_Review", methods=["POST"])
def physic_exp1st2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　前/physic_exp1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp1st2_video',methods =["post"])
def physic_exp1st2_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp1st2_mihyouka_video',methods =["post"])
def physic_exp1st2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/physic_exp1st3")
def physic_exp1st3():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　前/physic_exp1st3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp1st3_Review',methods = ["post"])
def physic_exp1st3_Review():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp1st3_mihyouka_Review", methods=["POST"])
def physic_exp1st3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　前/physic_exp1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp1st3_video',methods =["post"])
def physic_exp1st3_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp1st3_mihyouka_video',methods =["post"])
def physic_exp1st3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/physic_exp1st4")
def physic_exp1st4():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　前/physic_exp1st4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp1st4_Review',methods = ["post"])
def physic_exp1st4_Review():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp1st4_mihyouka_Review", methods=["POST"])
def physic_exp1st4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　前/physic_exp1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp1st4_video',methods =["post"])
def physic_exp1st4_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp1st4_mihyouka_video',methods =["post"])
def physic_exp1st4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/physic_exp1st5")
def physic_exp1st5():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　前/physic_exp1st5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp1st5_Review',methods = ["post"])
def physic_exp1st5_Review():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp1st5_mihyouka_Review", methods=["POST"])
def physic_exp1st5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　前/physic_exp1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp1st5_video',methods =["post"])
def physic_exp1st5_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp1st5_mihyouka_video',methods =["post"])
def physic_exp1st5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/physic_exp1st6")
def physic_exp1st6():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　前/physic_exp1st6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp1st6_Review',methods = ["post"])
def physic_exp1st6_Review():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp1st6_mihyouka_Review", methods=["POST"])
def physic_exp1st6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　前/physic_exp1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp1st6_video',methods =["post"])
def physic_exp1st6_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp1st6_mihyouka_video',methods =["post"])
def physic_exp1st6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/physic_exp1st7")
def physic_exp1st7():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　前/physic_exp1st7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp1st7_Review',methods = ["post"])
def physic_exp1st7_Review():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp1st7_mihyouka_Review", methods=["POST"])
def physic_exp1st7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　前/physic_exp1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp1st7_video',methods =["post"])
def physic_exp1st7_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp1st7_mihyouka_video',methods =["post"])
def physic_exp1st7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/physic_exp1st8")
def physic_exp1st8():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　前/physic_exp1st8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp1st8_Review',methods = ["post"])
def physic_exp1st8_Review():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp1st8_mihyouka_Review", methods=["POST"])
def physic_exp1st8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　前/physic_exp1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp1st8_video',methods =["post"])
def physic_exp1st8_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp1st8_mihyouka_video',methods =["post"])
def physic_exp1st8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/physic_exp1st9")
def physic_exp1st9():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　前/physic_exp1st9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp1st9_Review',methods = ["post"])
def physic_exp1st9_Review():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp1st9_mihyouka_Review", methods=["POST"])
def physic_exp1st9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　前/physic_exp1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp1st9_video',methods =["post"])
def physic_exp1st9_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp1st9_mihyouka_video',methods =["post"])
def physic_exp1st9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/physic_exp1st10")
def physic_exp1st10():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　前/physic_exp1st10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp1st10_Review',methods = ["post"])
def physic_exp1st10_Review():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp1st10_mihyouka_Review", methods=["POST"])
def physic_exp1st10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　前/physic_exp1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp1st10_video',methods =["post"])
def physic_exp1st10_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp1st10_mihyouka_video',methods =["post"])
def physic_exp1st10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/physic_exp1st11")
def physic_exp1st11():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/物理実験　前/physic_exp1st11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/physic_exp1st11_Review',methods = ["post"])
def physic_exp1st11_Review():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/physic_exp1st11_mihyouka_Review", methods=["POST"])
def physic_exp1st11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/物理実験　前/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/物理実験　前/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/物理実験　前/physic_exp1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/physic_exp1st11_video',methods =["post"])
def physic_exp1st11_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/physic_exp1st11_mihyouka_video',methods =["post"])
def physic_exp1st11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/物理実験　前/物理実験　前.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/物理実験　前/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/物理実験　前/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/物理実験　前/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/物理実験　前/physic_exp1st11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################文学１############################
################################################################################################
@app.route("/literature1_")
def literature1_():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/文学１/literature1__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/literature1_1")
def literature1_1():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学１/literature1_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature1_1_Review',methods = ["post"])
def literature1_1_Review():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature1_1_mihyouka_Review", methods=["POST"])
def literature1_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学１/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学１/literature1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature1_1_video',methods =["post"])
def literature1_1_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学１/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature1_1_mihyouka_video',methods =["post"])
def literature1_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学１/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/literature1_2")
def literature1_2():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学１/literature1_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature1_2_Review',methods = ["post"])
def literature1_2_Review():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature1_2_mihyouka_Review", methods=["POST"])
def literature1_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学１/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学１/literature1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature1_2_video',methods =["post"])
def literature1_2_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学１/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature1_2_mihyouka_video',methods =["post"])
def literature1_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学１/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/literature1_3")
def literature1_3():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学１/literature1_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature1_3_Review',methods = ["post"])
def literature1_3_Review():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature1_3_mihyouka_Review", methods=["POST"])
def literature1_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学１/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学１/literature1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature1_3_video',methods =["post"])
def literature1_3_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学１/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature1_3_mihyouka_video',methods =["post"])
def literature1_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学１/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/literature1_4")
def literature1_4():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学１/literature1_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature1_4_Review',methods = ["post"])
def literature1_4_Review():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature1_4_mihyouka_Review", methods=["POST"])
def literature1_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学１/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学１/literature1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature1_4_video',methods =["post"])
def literature1_4_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学１/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature1_4_mihyouka_video',methods =["post"])
def literature1_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学１/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/literature1_5")
def literature1_5():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学１/literature1_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature1_5_Review',methods = ["post"])
def literature1_5_Review():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature1_5_mihyouka_Review", methods=["POST"])
def literature1_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学１/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学１/literature1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature1_5_video',methods =["post"])
def literature1_5_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学１/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature1_5_mihyouka_video',methods =["post"])
def literature1_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学１/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/literature1_6")
def literature1_6():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学１/literature1_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature1_6_Review',methods = ["post"])
def literature1_6_Review():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学１/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature1_6_mihyouka_Review", methods=["POST"])
def literature1_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学１/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学１/literature1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature1_6_video',methods =["post"])
def literature1_6_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学１/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature1_6_mihyouka_video',methods =["post"])
def literature1_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学１/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/literature1_7")
def literature1_7():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学１/literature1_7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature1_7_Review',methods = ["post"])
def literature1_7_Review():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学１/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature1_7_mihyouka_Review", methods=["POST"])
def literature1_7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学１/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学１/literature1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature1_7_video',methods =["post"])
def literature1_7_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学１/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature1_7_mihyouka_video',methods =["post"])
def literature1_7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学１/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/literature1_8")
def literature1_8():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学１/literature1_8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature1_8_Review',methods = ["post"])
def literature1_8_Review():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学１/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature1_8_mihyouka_Review", methods=["POST"])
def literature1_8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学１/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学１/literature1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature1_8_video',methods =["post"])
def literature1_8_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学１/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature1_8_mihyouka_video',methods =["post"])
def literature1_8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学１/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/literature1_9")
def literature1_9():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学１/literature1_9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature1_9_Review',methods = ["post"])
def literature1_9_Review():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学１/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature1_9_mihyouka_Review", methods=["POST"])
def literature1_9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学１/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学１/literature1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature1_9_video',methods =["post"])
def literature1_9_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学１/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature1_9_mihyouka_video',methods =["post"])
def literature1_9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学１/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/literature1_10")
def literature1_10():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学１/literature1_10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature1_10_Review',methods = ["post"])
def literature1_10_Review():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学１/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature1_10_mihyouka_Review", methods=["POST"])
def literature1_10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学１/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学１/literature1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature1_10_video',methods =["post"])
def literature1_10_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学１/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature1_10_mihyouka_video',methods =["post"])
def literature1_10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学１/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/literature1_11")
def literature1_11():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学１/literature1_11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature1_11_Review',methods = ["post"])
def literature1_11_Review():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学１/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature1_11_mihyouka_Review", methods=["POST"])
def literature1_11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学１/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学１/literature1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature1_11_video',methods =["post"])
def literature1_11_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学１/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature1_11_mihyouka_video',methods =["post"])
def literature1_11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学１/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/literature1_12")
def literature1_12():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学１/literature1_12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature1_12_Review',methods = ["post"])
def literature1_12_Review():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学１/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature1_12_mihyouka_Review", methods=["POST"])
def literature1_12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学１/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学１/literature1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature1_12_video',methods =["post"])
def literature1_12_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学１/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature1_12_mihyouka_video',methods =["post"])
def literature1_12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学１/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/literature1_13")
def literature1_13():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学１/literature1_13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature1_13_Review',methods = ["post"])
def literature1_13_Review():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学１/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature1_13_mihyouka_Review", methods=["POST"])
def literature1_13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学１/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学１/literature1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature1_13_video',methods =["post"])
def literature1_13_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学１/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature1_13_mihyouka_video',methods =["post"])
def literature1_13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学１/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/literature1_14")
def literature1_14():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学１/literature1_14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature1_14_Review',methods = ["post"])
def literature1_14_Review():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学１/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature1_14_mihyouka_Review", methods=["POST"])
def literature1_14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学１/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学１/literature1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature1_14_video',methods =["post"])
def literature1_14_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学１/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature1_14_mihyouka_video',methods =["post"])
def literature1_14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学１/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/literature1_15")
def literature1_15():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学１/literature1_15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature1_15_Review',methods = ["post"])
def literature1_15_Review():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学１/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature1_15_mihyouka_Review", methods=["POST"])
def literature1_15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学１/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学１/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学１/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学１/literature1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature1_15_video',methods =["post"])
def literature1_15_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学１/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature1_15_mihyouka_video',methods =["post"])
def literature1_15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学１/文学１.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学１/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学１/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学１/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学１/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学１/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学１/literature1_15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################文学２############################
################################################################################################
@app.route("/literature2_")
def literature2_():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/文学２/literature2__syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/literature2_1")
def literature2_1():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学２/literature2_1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature2_1_Review',methods = ["post"])
def literature2_1_Review():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature2_1_mihyouka_Review", methods=["POST"])
def literature2_1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学２/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学２/literature2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature2_1_video',methods =["post"])
def literature2_1_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学２/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature2_1_mihyouka_video',methods =["post"])
def literature2_1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学２/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/literature2_2")
def literature2_2():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学２/literature2_2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature2_2_Review',methods = ["post"])
def literature2_2_Review():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature2_2_mihyouka_Review", methods=["POST"])
def literature2_2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学２/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学２/literature2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature2_2_video',methods =["post"])
def literature2_2_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学２/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature2_2_mihyouka_video',methods =["post"])
def literature2_2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学２/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/literature2_3")
def literature2_3():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学２/literature2_3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature2_3_Review',methods = ["post"])
def literature2_3_Review():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature2_3_mihyouka_Review", methods=["POST"])
def literature2_3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学２/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学２/literature2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature2_3_video',methods =["post"])
def literature2_3_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学２/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature2_3_mihyouka_video',methods =["post"])
def literature2_3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学２/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/literature2_4")
def literature2_4():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学２/literature2_4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature2_4_Review',methods = ["post"])
def literature2_4_Review():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature2_4_mihyouka_Review", methods=["POST"])
def literature2_4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学２/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学２/literature2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature2_4_video',methods =["post"])
def literature2_4_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学２/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature2_4_mihyouka_video',methods =["post"])
def literature2_4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学２/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/literature2_5")
def literature2_5():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学２/literature2_5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature2_5_Review',methods = ["post"])
def literature2_5_Review():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature2_5_mihyouka_Review", methods=["POST"])
def literature2_5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学２/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学２/literature2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature2_5_video',methods =["post"])
def literature2_5_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学２/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature2_5_mihyouka_video',methods =["post"])
def literature2_5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学２/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/literature2_6")
def literature2_6():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学２/literature2_6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature2_6_Review',methods = ["post"])
def literature2_6_Review():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学２/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature2_6_mihyouka_Review", methods=["POST"])
def literature2_6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学２/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学２/literature2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature2_6_video',methods =["post"])
def literature2_6_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学２/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature2_6_mihyouka_video',methods =["post"])
def literature2_6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学２/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/literature2_7")
def literature2_7():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学２/literature2_7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature2_7_Review',methods = ["post"])
def literature2_7_Review():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学２/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature2_7_mihyouka_Review", methods=["POST"])
def literature2_7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学２/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学２/literature2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature2_7_video',methods =["post"])
def literature2_7_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学２/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature2_7_mihyouka_video',methods =["post"])
def literature2_7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学２/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/literature2_8")
def literature2_8():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学２/literature2_8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature2_8_Review',methods = ["post"])
def literature2_8_Review():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学２/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature2_8_mihyouka_Review", methods=["POST"])
def literature2_8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学２/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学２/literature2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature2_8_video',methods =["post"])
def literature2_8_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学２/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature2_8_mihyouka_video',methods =["post"])
def literature2_8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学２/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/literature2_9")
def literature2_9():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学２/literature2_9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature2_9_Review',methods = ["post"])
def literature2_9_Review():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学２/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature2_9_mihyouka_Review", methods=["POST"])
def literature2_9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学２/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学２/literature2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature2_9_video',methods =["post"])
def literature2_9_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学２/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature2_9_mihyouka_video',methods =["post"])
def literature2_9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学２/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/literature2_10")
def literature2_10():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/文学２/literature2_10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/literature2_10_Review',methods = ["post"])
def literature2_10_Review():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/文学２/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/literature2_10_mihyouka_Review", methods=["POST"])
def literature2_10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/文学２/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/文学２/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/文学２/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/文学２/literature2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/literature2_10_video',methods =["post"])
def literature2_10_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/文学２/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/literature2_10_mihyouka_video',methods =["post"])
def literature2_10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/文学２/文学２.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/文学２/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/文学２/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/文学２/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/文学２/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/文学２/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/文学２/literature2_10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################法学１　前期############################
################################################################################################
@app.route("/law1_1st")
def law1_1st():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/法学１　前期/law1_1st_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/law1_1st1")
def law1_1st1():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/法学１　前期/law1_1st1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/law1_1st1_Review',methods = ["post"])
def law1_1st1_Review():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学１　前期/law1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/law1_1st1_mihyouka_Review", methods=["POST"])
def law1_1st1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/法学１　前期/law1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/law1_1st1_video',methods =["post"])
def law1_1st1_video():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/法学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学１　前期/law1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/law1_1st1_mihyouka_video',methods =["post"])
def law1_1st1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/法学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学１　前期/law1_1st1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/law1_1st2")
def law1_1st2():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/法学１　前期/law1_1st2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/law1_1st2_Review',methods = ["post"])
def law1_1st2_Review():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学１　前期/law1_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/law1_1st2_mihyouka_Review", methods=["POST"])
def law1_1st2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/法学１　前期/law1_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/law1_1st2_video',methods =["post"])
def law1_1st2_video():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/法学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学１　前期/law1_1st2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/law1_1st2_mihyouka_video',methods =["post"])
def law1_1st2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/法学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学１　前期/law1_1st2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/law1_1st3")
def law1_1st3():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/法学１　前期/law1_1st3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/law1_1st3_Review',methods = ["post"])
def law1_1st3_Review():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学１　前期/law1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/law1_1st3_mihyouka_Review", methods=["POST"])
def law1_1st3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/法学１　前期/law1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/law1_1st3_video',methods =["post"])
def law1_1st3_video():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/法学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学１　前期/law1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/law1_1st3_mihyouka_video',methods =["post"])
def law1_1st3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/法学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学１　前期/law1_1st3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/law1_1st4")
def law1_1st4():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/法学１　前期/law1_1st4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/law1_1st4_Review',methods = ["post"])
def law1_1st4_Review():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学１　前期/law1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/law1_1st4_mihyouka_Review", methods=["POST"])
def law1_1st4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/法学１　前期/law1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/law1_1st4_video',methods =["post"])
def law1_1st4_video():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/法学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学１　前期/law1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/law1_1st4_mihyouka_video',methods =["post"])
def law1_1st4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/法学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学１　前期/law1_1st4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/law1_1st5")
def law1_1st5():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/法学１　前期/law1_1st5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/law1_1st5_Review',methods = ["post"])
def law1_1st5_Review():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学１　前期/law1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/law1_1st5_mihyouka_Review", methods=["POST"])
def law1_1st5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/法学１　前期/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/法学１　前期/law1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/law1_1st5_video',methods =["post"])
def law1_1st5_video():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/法学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学１　前期/law1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/law1_1st5_mihyouka_video',methods =["post"])
def law1_1st5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/法学１　前期/法学１　前期.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/法学１　前期/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/法学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学１　前期/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学１　前期/law1_1st5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################法学２（工学部・看護学部２年生）############################
################################################################################################
@app.route("/law2_2grade")
def law2_2grade():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/法学２（工学部・看護学部２年生）/law2_2grade_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/law2_2grade1")
def law2_2grade1():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/law2_2grade1_Review',methods = ["post"])
def law2_2grade1_Review():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/law2_2grade1_mihyouka_Review", methods=["POST"])
def law2_2grade1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/law2_2grade1_video',methods =["post"])
def law2_2grade1_video():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/law2_2grade1_mihyouka_video',methods =["post"])
def law2_2grade1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/law2_2grade2")
def law2_2grade2():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/law2_2grade2_Review',methods = ["post"])
def law2_2grade2_Review():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/law2_2grade2_mihyouka_Review", methods=["POST"])
def law2_2grade2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/law2_2grade2_video',methods =["post"])
def law2_2grade2_video():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/law2_2grade2_mihyouka_video',methods =["post"])
def law2_2grade2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/law2_2grade3")
def law2_2grade3():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/law2_2grade3_Review',methods = ["post"])
def law2_2grade3_Review():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/law2_2grade3_mihyouka_Review", methods=["POST"])
def law2_2grade3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/law2_2grade3_video',methods =["post"])
def law2_2grade3_video():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/law2_2grade3_mihyouka_video',methods =["post"])
def law2_2grade3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/law2_2grade4")
def law2_2grade4():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/law2_2grade4_Review',methods = ["post"])
def law2_2grade4_Review():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/law2_2grade4_mihyouka_Review", methods=["POST"])
def law2_2grade4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/law2_2grade4_video',methods =["post"])
def law2_2grade4_video():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/law2_2grade4_mihyouka_video',methods =["post"])
def law2_2grade4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/law2_2grade5")
def law2_2grade5():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/law2_2grade5_Review',methods = ["post"])
def law2_2grade5_Review():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/law2_2grade5_mihyouka_Review", methods=["POST"])
def law2_2grade5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/law2_2grade5_video',methods =["post"])
def law2_2grade5_video():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/law2_2grade5_mihyouka_video',methods =["post"])
def law2_2grade5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/law2_2grade6")
def law2_2grade6():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/law2_2grade6_Review',methods = ["post"])
def law2_2grade6_Review():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/law2_2grade6_mihyouka_Review", methods=["POST"])
def law2_2grade6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/law2_2grade6_video',methods =["post"])
def law2_2grade6_video():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/law2_2grade6_mihyouka_video',methods =["post"])
def law2_2grade6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/law2_2grade7")
def law2_2grade7():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/law2_2grade7_Review',methods = ["post"])
def law2_2grade7_Review():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/law2_2grade7_mihyouka_Review", methods=["POST"])
def law2_2grade7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/law2_2grade7_video',methods =["post"])
def law2_2grade7_video():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/law2_2grade7_mihyouka_video',methods =["post"])
def law2_2grade7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/法学２（工学部・看護学部２年生）.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/法学２（工学部・看護学部２年生）/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/法学２（工学部・看護学部２年生）/law2_2grade7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################倫理学############################
################################################################################################
@app.route("/ethic")
def ethic():
    df_key = pd.read_csv("Kamoku/倫理学/倫理学.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/倫理学/ethic_syr.html', 
                            key_word1 = keyword[0]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/ethic1")
def ethic1():
    df_key = pd.read_csv("Kamoku/倫理学/倫理学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/倫理学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/倫理学/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/倫理学/ethic1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/ethic1_Review',methods = ["post"])
def ethic1_Review():
    df_key = pd.read_csv("Kamoku/倫理学/倫理学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/倫理学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/倫理学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/倫理学/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/倫理学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/倫理学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/倫理学/ethic1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/ethic1_mihyouka_Review", methods=["POST"])
def ethic1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/倫理学/倫理学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/倫理学/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/倫理学/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/倫理学/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/倫理学/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/倫理学/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/倫理学/ethic1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/ethic1_video',methods =["post"])
def ethic1_video():
    df_key = pd.read_csv("Kamoku/倫理学/倫理学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/倫理学/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/倫理学/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/倫理学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/倫理学/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/倫理学/ethic1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/ethic1_mihyouka_video',methods =["post"])
def ethic1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/倫理学/倫理学.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/倫理学/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/倫理学/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/倫理学/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/倫理学/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/倫理学/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/倫理学/ethic1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################論理回路応用############################
################################################################################################
@app.route("/logic_circuit_app")
def logic_circuit_app():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/論理回路応用/logic_circuit_app_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/logic_circuit_app1")
def logic_circuit_app1():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路応用/logic_circuit_app1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_app1_Review',methods = ["post"])
def logic_circuit_app1_Review():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_app1_mihyouka_Review", methods=["POST"])
def logic_circuit_app1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路応用/logic_circuit_app1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_app1_video',methods =["post"])
def logic_circuit_app1_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_app1_mihyouka_video',methods =["post"])
def logic_circuit_app1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/logic_circuit_app2")
def logic_circuit_app2():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路応用/logic_circuit_app2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_app2_Review',methods = ["post"])
def logic_circuit_app2_Review():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_app2_mihyouka_Review", methods=["POST"])
def logic_circuit_app2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路応用/logic_circuit_app2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_app2_video',methods =["post"])
def logic_circuit_app2_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_app2_mihyouka_video',methods =["post"])
def logic_circuit_app2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/logic_circuit_app3")
def logic_circuit_app3():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路応用/logic_circuit_app3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_app3_Review',methods = ["post"])
def logic_circuit_app3_Review():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_app3_mihyouka_Review", methods=["POST"])
def logic_circuit_app3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路応用/logic_circuit_app3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_app3_video',methods =["post"])
def logic_circuit_app3_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_app3_mihyouka_video',methods =["post"])
def logic_circuit_app3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/logic_circuit_app4")
def logic_circuit_app4():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路応用/logic_circuit_app4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_app4_Review',methods = ["post"])
def logic_circuit_app4_Review():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_app4_mihyouka_Review", methods=["POST"])
def logic_circuit_app4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路応用/logic_circuit_app4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_app4_video',methods =["post"])
def logic_circuit_app4_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_app4_mihyouka_video',methods =["post"])
def logic_circuit_app4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/logic_circuit_app5")
def logic_circuit_app5():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路応用/logic_circuit_app5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_app5_Review',methods = ["post"])
def logic_circuit_app5_Review():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_app5_mihyouka_Review", methods=["POST"])
def logic_circuit_app5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路応用/logic_circuit_app5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_app5_video',methods =["post"])
def logic_circuit_app5_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_app5_mihyouka_video',methods =["post"])
def logic_circuit_app5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/logic_circuit_app6")
def logic_circuit_app6():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路応用/logic_circuit_app6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_app6_Review',methods = ["post"])
def logic_circuit_app6_Review():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_app6_mihyouka_Review", methods=["POST"])
def logic_circuit_app6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路応用/logic_circuit_app6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_app6_video',methods =["post"])
def logic_circuit_app6_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_app6_mihyouka_video',methods =["post"])
def logic_circuit_app6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/logic_circuit_app7")
def logic_circuit_app7():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路応用/logic_circuit_app7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_app7_Review',methods = ["post"])
def logic_circuit_app7_Review():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_app7_mihyouka_Review", methods=["POST"])
def logic_circuit_app7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路応用/logic_circuit_app7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_app7_video',methods =["post"])
def logic_circuit_app7_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_app7_mihyouka_video',methods =["post"])
def logic_circuit_app7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/logic_circuit_app8")
def logic_circuit_app8():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路応用/logic_circuit_app8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_app8_Review',methods = ["post"])
def logic_circuit_app8_Review():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_app8_mihyouka_Review", methods=["POST"])
def logic_circuit_app8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路応用/logic_circuit_app8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_app8_video',methods =["post"])
def logic_circuit_app8_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_app8_mihyouka_video',methods =["post"])
def logic_circuit_app8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/logic_circuit_app9")
def logic_circuit_app9():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路応用/logic_circuit_app9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_app9_Review',methods = ["post"])
def logic_circuit_app9_Review():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_app9_mihyouka_Review", methods=["POST"])
def logic_circuit_app9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路応用/logic_circuit_app9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_app9_video',methods =["post"])
def logic_circuit_app9_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_app9_mihyouka_video',methods =["post"])
def logic_circuit_app9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/logic_circuit_app10")
def logic_circuit_app10():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路応用/logic_circuit_app10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_app10_Review',methods = ["post"])
def logic_circuit_app10_Review():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_app10_mihyouka_Review", methods=["POST"])
def logic_circuit_app10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路応用/logic_circuit_app10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_app10_video',methods =["post"])
def logic_circuit_app10_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_app10_mihyouka_video',methods =["post"])
def logic_circuit_app10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/logic_circuit_app11")
def logic_circuit_app11():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路応用/logic_circuit_app11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_app11_Review',methods = ["post"])
def logic_circuit_app11_Review():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_app11_mihyouka_Review", methods=["POST"])
def logic_circuit_app11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路応用/logic_circuit_app11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_app11_video',methods =["post"])
def logic_circuit_app11_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_app11_mihyouka_video',methods =["post"])
def logic_circuit_app11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/logic_circuit_app12")
def logic_circuit_app12():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路応用/logic_circuit_app12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_app12_Review',methods = ["post"])
def logic_circuit_app12_Review():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_app12_mihyouka_Review", methods=["POST"])
def logic_circuit_app12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路応用/logic_circuit_app12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_app12_video',methods =["post"])
def logic_circuit_app12_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_app12_mihyouka_video',methods =["post"])
def logic_circuit_app12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/logic_circuit_app13")
def logic_circuit_app13():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路応用/logic_circuit_app13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_app13_Review',methods = ["post"])
def logic_circuit_app13_Review():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_app13_mihyouka_Review", methods=["POST"])
def logic_circuit_app13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路応用/logic_circuit_app13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_app13_video',methods =["post"])
def logic_circuit_app13_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_app13_mihyouka_video',methods =["post"])
def logic_circuit_app13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/logic_circuit_app14")
def logic_circuit_app14():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路応用/logic_circuit_app14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_app14_Review',methods = ["post"])
def logic_circuit_app14_Review():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_app14_mihyouka_Review", methods=["POST"])
def logic_circuit_app14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路応用/logic_circuit_app14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_app14_video',methods =["post"])
def logic_circuit_app14_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_app14_mihyouka_video',methods =["post"])
def logic_circuit_app14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/logic_circuit_app15")
def logic_circuit_app15():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路応用/logic_circuit_app15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_app15_Review',methods = ["post"])
def logic_circuit_app15_Review():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_app15_mihyouka_Review", methods=["POST"])
def logic_circuit_app15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路応用/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路応用/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路応用/logic_circuit_app15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_app15_video',methods =["post"])
def logic_circuit_app15_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_app15_mihyouka_video',methods =["post"])
def logic_circuit_app15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路応用/論理回路応用.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路応用/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路応用/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路応用/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路応用/logic_circuit_app15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )



################################################################################################
#############################################論理回路基礎############################
################################################################################################
@app.route("/logic_circuit_base")
def logic_circuit_base():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []

    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    return render_template('/論理回路基礎/logic_circuit_base_syr.html', 
                            key_word1 = keyword[0],
                            key_word2 = keyword[1],
                            key_word3 = keyword[2],
                            key_word4 = keyword[3],
                            key_word5 = keyword[4],
                            key_word6 = keyword[5],
                            key_word7 = keyword[6],
                            key_word8 = keyword[7],
                            key_word9 = keyword[8],
                            key_word10 = keyword[9],
                            key_word11 = keyword[10],
                            key_word12 = keyword[11],
                            key_word13 = keyword[12],
                            key_word14 = keyword[13],
                            key_word15 = keyword[14]
                            )

###########キーワード1つ目########################
#################################################
@app.route("/logic_circuit_base1")
def logic_circuit_base1():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai0/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路基礎/logic_circuit_base1.html", title= keyword[0],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_base1_Review',methods = ["post"])
def logic_circuit_base1_Review():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai0/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_base1_mihyouka_Review", methods=["POST"])
def logic_circuit_base1_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai0/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai0/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai0/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai0/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai0/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路基礎/logic_circuit_base1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_base1_video',methods =["post"])
def logic_circuit_base1_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai0/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_base1_mihyouka_video',methods =["post"])
def logic_circuit_base1_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai0/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base1.html",title = keyword[0],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード2つ目########################
#################################################
@app.route("/logic_circuit_base2")
def logic_circuit_base2():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai1/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路基礎/logic_circuit_base2.html", title= keyword[1],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_base2_Review',methods = ["post"])
def logic_circuit_base2_Review():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai1/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_base2_mihyouka_Review", methods=["POST"])
def logic_circuit_base2_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai1/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai1/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai1/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai1/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai1/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路基礎/logic_circuit_base2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_base2_video',methods =["post"])
def logic_circuit_base2_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai1/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base2.html",title = keyword[1],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_base2_mihyouka_video',methods =["post"])
def logic_circuit_base2_mihyouka_video():
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai1/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base2.html",
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[1],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード3つ目########################
#################################################
@app.route("/logic_circuit_base3")
def logic_circuit_base3():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai2/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路基礎/logic_circuit_base3.html", title= keyword[2],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_base3_Review',methods = ["post"])
def logic_circuit_base3_Review():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai2/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_base3_mihyouka_Review", methods=["POST"])
def logic_circuit_base3_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai2/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai2/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai2/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai2/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai2/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路基礎/logic_circuit_base3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_base3_video',methods =["post"])
def logic_circuit_base3_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai2/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_base3_mihyouka_video',methods =["post"])
def logic_circuit_base3_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai2/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base3.html",title = keyword[2],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード4つ目########################
#################################################
@app.route("/logic_circuit_base4")
def logic_circuit_base4():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai3/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路基礎/logic_circuit_base4.html", title= keyword[3],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_base4_Review',methods = ["post"])
def logic_circuit_base4_Review():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai3/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_base4_mihyouka_Review", methods=["POST"])
def logic_circuit_base4_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai3/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai3/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai3/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai3/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai3/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路基礎/logic_circuit_base4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_base4_video',methods =["post"])
def logic_circuit_base4_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai3/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_base4_mihyouka_video',methods =["post"])
def logic_circuit_base4_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai3/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base4.html",title = keyword[3],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード5つ目########################
#################################################
@app.route("/logic_circuit_base5")
def logic_circuit_base5():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai4/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路基礎/logic_circuit_base5.html", title= keyword[4],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_base5_Review',methods = ["post"])
def logic_circuit_base5_Review():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai4/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_base5_mihyouka_Review", methods=["POST"])
def logic_circuit_base5_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai4/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai4/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai4/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai4/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai4/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路基礎/logic_circuit_base5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_base5_video',methods =["post"])
def logic_circuit_base5_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai4/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_base5_mihyouka_video',methods =["post"])
def logic_circuit_base5_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai4/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base5.html",title = keyword[4],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード6つ目########################
#################################################
@app.route("/logic_circuit_base6")
def logic_circuit_base6():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai5/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路基礎/logic_circuit_base6.html", title= keyword[5],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_base6_Review',methods = ["post"])
def logic_circuit_base6_Review():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai5/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_base6_mihyouka_Review", methods=["POST"])
def logic_circuit_base6_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai5/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai5/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai5/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai5/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai5/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路基礎/logic_circuit_base6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_base6_video',methods =["post"])
def logic_circuit_base6_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai5/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_base6_mihyouka_video',methods =["post"])
def logic_circuit_base6_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai5/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base6.html",title = keyword[5],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード7つ目########################
#################################################
@app.route("/logic_circuit_base7")
def logic_circuit_base7():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai6/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路基礎/logic_circuit_base7.html", title= keyword[6],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_base7_Review',methods = ["post"])
def logic_circuit_base7_Review():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai6/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_base7_mihyouka_Review", methods=["POST"])
def logic_circuit_base7_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai6/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai6/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai6/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai6/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai6/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路基礎/logic_circuit_base7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_base7_video',methods =["post"])
def logic_circuit_base7_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai6/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_base7_mihyouka_video',methods =["post"])
def logic_circuit_base7_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai6/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base7.html",title = keyword[6],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード8つ目########################
#################################################
@app.route("/logic_circuit_base8")
def logic_circuit_base8():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai7/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路基礎/logic_circuit_base8.html", title= keyword[7],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_base8_Review',methods = ["post"])
def logic_circuit_base8_Review():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai7/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_base8_mihyouka_Review", methods=["POST"])
def logic_circuit_base8_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai7/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai7/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai7/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai7/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai7/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路基礎/logic_circuit_base8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_base8_video',methods =["post"])
def logic_circuit_base8_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai7/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_base8_mihyouka_video',methods =["post"])
def logic_circuit_base8_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai7/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base8.html",title = keyword[7],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード9つ目########################
#################################################
@app.route("/logic_circuit_base9")
def logic_circuit_base9():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai8/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路基礎/logic_circuit_base9.html", title= keyword[8],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_base9_Review',methods = ["post"])
def logic_circuit_base9_Review():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai8/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_base9_mihyouka_Review", methods=["POST"])
def logic_circuit_base9_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai8/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai8/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai8/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai8/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai8/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路基礎/logic_circuit_base9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_base9_video',methods =["post"])
def logic_circuit_base9_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai8/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_base9_mihyouka_video',methods =["post"])
def logic_circuit_base9_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai8/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base9.html",title = keyword[8],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード10つ目########################
#################################################
@app.route("/logic_circuit_base10")
def logic_circuit_base10():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai9/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路基礎/logic_circuit_base10.html", title= keyword[9],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_base10_Review',methods = ["post"])
def logic_circuit_base10_Review():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai9/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_base10_mihyouka_Review", methods=["POST"])
def logic_circuit_base10_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai9/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai9/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai9/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai9/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai9/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路基礎/logic_circuit_base10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_base10_video',methods =["post"])
def logic_circuit_base10_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai9/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_base10_mihyouka_video',methods =["post"])
def logic_circuit_base10_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai9/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base10.html",title = keyword[9],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード11つ目########################
#################################################
@app.route("/logic_circuit_base11")
def logic_circuit_base11():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai10/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路基礎/logic_circuit_base11.html", title= keyword[10],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_base11_Review',methods = ["post"])
def logic_circuit_base11_Review():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai10/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_base11_mihyouka_Review", methods=["POST"])
def logic_circuit_base11_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai10/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai10/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai10/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai10/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai10/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路基礎/logic_circuit_base11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_base11_video',methods =["post"])
def logic_circuit_base11_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai10/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_base11_mihyouka_video',methods =["post"])
def logic_circuit_base11_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai10/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base11.html",title = keyword[10],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード12つ目########################
#################################################
@app.route("/logic_circuit_base12")
def logic_circuit_base12():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai11/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路基礎/logic_circuit_base12.html", title= keyword[11],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_base12_Review',methods = ["post"])
def logic_circuit_base12_Review():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai11/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_base12_mihyouka_Review", methods=["POST"])
def logic_circuit_base12_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai11/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai11/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai11/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai11/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai11/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路基礎/logic_circuit_base12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_base12_video',methods =["post"])
def logic_circuit_base12_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai11/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_base12_mihyouka_video',methods =["post"])
def logic_circuit_base12_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai11/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base12.html",title = keyword[11],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード13つ目########################
#################################################
@app.route("/logic_circuit_base13")
def logic_circuit_base13():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai12/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路基礎/logic_circuit_base13.html", title= keyword[12],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_base13_Review',methods = ["post"])
def logic_circuit_base13_Review():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai12/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_base13_mihyouka_Review", methods=["POST"])
def logic_circuit_base13_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai12/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai12/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai12/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai12/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai12/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路基礎/logic_circuit_base13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_base13_video',methods =["post"])
def logic_circuit_base13_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai12/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_base13_mihyouka_video',methods =["post"])
def logic_circuit_base13_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai12/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base13.html",title = keyword[12],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード14つ目########################
#################################################
@app.route("/logic_circuit_base14")
def logic_circuit_base14():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai13/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路基礎/logic_circuit_base14.html", title= keyword[13],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_base14_Review',methods = ["post"])
def logic_circuit_base14_Review():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai13/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_base14_mihyouka_Review", methods=["POST"])
def logic_circuit_base14_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai13/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai13/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai13/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai13/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai13/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路基礎/logic_circuit_base14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_base14_video',methods =["post"])
def logic_circuit_base14_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai13/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_base14_mihyouka_video',methods =["post"])
def logic_circuit_base14_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai13/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base14.html",title = keyword[13],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


###########キーワード15つ目########################
#################################################
@app.route("/logic_circuit_base15")
def logic_circuit_base15():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    
    #HP
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")

    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []

    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    number = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{number[i]}"').index)))
    
    update_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai14/kyouzaiDB.csv", encoding="cp932")
    score_list=[]
    #Credibility_scoreをscore_listに追加する（上から３つ）
    for i in range(3):
        score_list.append(update_df.iat[i,3])
    

    #youtubeについて
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))

    video_update_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_update_df.iat[i,4])


    return render_template("/論理回路基礎/logic_circuit_base15.html", title= keyword[14],
            kyouzai_title1 = kyouzai_title_list[0], kyouzai_url1 = kyouzai_url_list[0],
            kyouzai_title2 = kyouzai_title_list[1], kyouzai_url2 = kyouzai_url_list[1],
            kyouzai_title3 = kyouzai_title_list[2], kyouzai_url3 = kyouzai_url_list[2],
            mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
            mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
            mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
            length1 = length[0], length2=length[1], length3=length[2],
            video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
            video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
            video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
            mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
            mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
            mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
            mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
            video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
            score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
            video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
            )

@app.route('/logic_circuit_base15_Review',methods = ["post"])
def logic_circuit_base15_Review():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    HPnumber = kyouzaiDB.iloc[number,2]
    HPtitle = kyouzaiDB.iloc[number,0]
    HPurl = kyouzaiDB.iloc[number,1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    #レビューした日付と時間を取得する
    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    #上で取得したデータを review_list に保存する
    review_list = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)

    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai14/kyouzaiDB.csv"

    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)  
    Credibility_score, Ave_score = Credibility(S_score_norm, I_score_norm, C_score_norm, HPnumber, df)
    review_score = [HPtitle, HPurl, HPnumber, studentnumber, evaluation, text, date, Credibility_score, Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']
    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    kyouzai_title_list, kyouzai_url_list, mihyouka_kyouzai_title_list, mihyouka_kyouzai_url_list, length =\
         kousinn01(kyouzaiDB, Credibility_score, HPnumber,df,saveDB)
    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0], mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1], mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2], mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0], length2=length[1], length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route("/logic_circuit_base15_mihyouka_Review", methods=["POST"])
def logic_circuit_base15_mihyouka_Review():
    ##キーワード取得のための部分##
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])
    ############################

    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    number = int(request.form['number'])
    #index = list(kyouzaiDB.reset_index().query(f'Credibility_score == "{np.nan}"').index)
    index = list(kyouzaiDB.reset_index().query(f'Credibility_score.isnull()').index)
    HPnumber = kyouzaiDB.iloc[index[number],2]
    HPtitle = kyouzaiDB.iloc[index[number],0]
    HPurl = kyouzaiDB.iloc[index[number],1]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    review_list = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai14/review_prac.csv","a",encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_list)
    #評価によって並べ替える
    df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai14/review_prac.csv",encoding="cp932")
    saveDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai14/kyouzaiDB.csv"


    #Youtube
    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_kyouzai.csv', encoding="cp932")
    video_review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')

    video_title_list = []
    video_url_list = []
    video_id_list = []
    mihyouka_video_title_list = []
    mihyouka_video_url_list = []
    mihyouka_video_id_list = []
    video_length = []
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    yo = youtubeDB['Youtubenumber']

    for i in range(3):
        video_title_list.append(youtubeDB.iat[i,0])
        video_url_list.append(youtubeDB.iat[i,1])
        video_id_list.append(youtubeDB.iat[i,3])
        mihyouka_video_title_list.append(youtubeDB.iat[video_index[i],0])
        mihyouka_video_url_list.append(youtubeDB.iat[video_index[i],1])
        mihyouka_video_id_list.append(youtubeDB.iat[video_index[i],3])
        video_length.append(len(list(video_review_df.query(f'Youtubenumber == "{yo[i]}"').index)))


    S_score_norm = Similarity(df)
    I_score_norm = Informative(df)
    C_score_norm = Concentration(df)
    Credibility_score,Ave_score = Credibility(S_score_norm,I_score_norm,C_score_norm,HPnumber,df)
    review_score = [HPtitle,HPurl,HPnumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]

    with open("Kamoku/論理回路基礎/Kyouzai/kyouzai14/review_score.csv", "a", encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)

    kyouzai_title_list,kyouzai_url_list,mihyouka_kyouzai_title_list,mihyouka_kyouzai_url_list,length =\
         kousinn01(kyouzaiDB,Credibility_score,HPnumber,df,saveDB)

    kousinn_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai14/kyouzaiDB.csv",encoding="cp932")
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])
    

    return render_template("/論理回路基礎/logic_circuit_base15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3S = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )

@app.route('/logic_circuit_base15_video',methods =["post"])
def logic_circuit_base15_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    Youtubenumber = youtubeDB.iloc[number,2]
    Youtubetitel = youtubeDB.iloc[number,0]
    Youtubeurl = youtubeDB.iloc[number,1]
    Youtubeid = youtubeDB.iloc[number,3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']
    
    #レビューした学籍番号を取得
    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    #date = dtt.strftime("%Y/%#m/$#d %H:%M") 
    date = dtt.strftime("%Y/%-m/%-d %H:%M")
    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]

    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_Review.csv','a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)
    
    video_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_Review.csv',encoding='cp932')
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_kyouzai.csv"

    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score, Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai14/review_prac.csv",encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])

    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2])

@app.route('/logic_circuit_base15_mihyouka_video',methods =["post"])
def logic_circuit_base15_mihyouka_video():
    df_key = pd.read_csv("Kamoku/論理回路基礎/論理回路基礎.csv",encoding="cp932",names= ['key'])
    keyword = []
    for i in range(len(df_key)):
        keyword.append(df_key.loc[i,'key'])

    youtubeDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    number = int(request.form['number'])
    video_index = list(youtubeDB.query(f'Credibility_score.isnull()',engine='python').index)
    Youtubenumber = youtubeDB.iloc[video_index[number],2]
    Youtubetitel = youtubeDB.iloc[video_index[number],0]
    Youtubeurl = youtubeDB.iloc[video_index[number],1]
    Youtubeid = youtubeDB.iloc[video_index[number],3]
    evaluation = int(request.form['evaluation'])
    text = request.form['text']

    #studentnumber = session["user"]
    studentnumber = "2155016"

    dt = datetime.datetime.now()
    dtt = dt.replace(microsecond=0)
    date = dtt.strftime("%Y/%-m/%-d %H:%M")

    video_review = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Youtubeid]
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_Review.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(video_review)

    video_df = pd.read_csv("Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_Review.csv", encoding="cp932")
    save_videoDB = "Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_kyouzai.csv"
    
    S_score_norm = Similarity(video_df)
    I_score_norm = Informative(video_df)
    C_score_norm = Concentration(video_df)
    Credibility_score,Ave_score = Credibility_video(S_score_norm,I_score_norm,C_score_norm,Youtubenumber,video_df)
    review_score = [Youtubetitel,Youtubeurl,Youtubenumber,studentnumber,evaluation,text,date,Credibility_score,Ave_score]
    
    with open('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_score.csv', 'a',encoding="cp932",newline='') as f:
        writer = csv.writer(f,delimiter=',')
        writer.writerow(review_score)
    
    ##HP##
    kyouzaiDB = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/kyouzaiDB.csv', encoding="cp932")
    review_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/review_prac.csv',encoding='cp932')
    kyouzai_title_list = []
    kyouzai_url_list = []
    mihyouka_kyouzai_title_list = []
    mihyouka_kyouzai_url_list = []
    length = []
    index = list(kyouzaiDB.query(f'Credibility_score.isnull()',engine='python').index)
    a = kyouzaiDB['Hpnumber']

    for i in range(3):
        kyouzai_title_list.append(kyouzaiDB.iloc[i,0])
        kyouzai_url_list.append(kyouzaiDB.iloc[i,1])
        mihyouka_kyouzai_title_list.append(kyouzaiDB.iloc[index[i],0])
        mihyouka_kyouzai_url_list.append(kyouzaiDB.iloc[index[i],1])
        length.append(len(list(review_df.query(f'Hpnumber == "{a[i]}"').index)))
    
    
    kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/kyouzaiDB.csv',encoding='cp932')
    score_list = []
    for i in range(3):
        score_list.append(kousinn_df.iat[i,3])
    
    video_title_list,video_url_list,mihyouka_video_title_list,mihyouka_video_url_list,video_id_list,mihyouka_video_id_list,video_length =\
         video_kousinn00(youtubeDB,Credibility_score,Youtubenumber, video_df, save_videoDB)
    video_kousinn_df = pd.read_csv('Kamoku/論理回路基礎/Kyouzai/kyouzai14/video_kyouzai.csv',encoding='cp932')
    video_score_list = []
    for i in range(3):
        video_score_list.append(video_kousinn_df.iat[i,4])

    return render_template("/論理回路基礎/logic_circuit_base15.html",title = keyword[14],
    kyouzai_title1 = kyouzai_title_list[0],kyouzai_url1 = kyouzai_url_list[0],
    kyouzai_title2 = kyouzai_title_list[1],kyouzai_url2 = kyouzai_url_list[1],
    kyouzai_title3 = kyouzai_title_list[2],kyouzai_url3 = kyouzai_url_list[2],
    mihyouka_title1 = mihyouka_kyouzai_title_list[0],mihyouka_url1 = mihyouka_kyouzai_url_list[0],
    mihyouka_title2 = mihyouka_kyouzai_title_list[1],mihyouka_url2 = mihyouka_kyouzai_url_list[1],
    mihyouka_title3 = mihyouka_kyouzai_title_list[2],mihyouka_url3 = mihyouka_kyouzai_url_list[2],
    length1 = length[0],length2=length[1],length3=length[2],
    video_title1 = video_title_list[0],video_url1 = video_url_list[0],video_id1 = video_id_list[0],
    video_title2 = video_title_list[1],video_url2 = video_url_list[1],video_id2 = video_id_list[1],
    video_title3 = video_title_list[2],video_url3 = video_url_list[2],video_id3 = video_id_list[2],
    mihyouka_video_title1 = mihyouka_video_title_list[0],mihyouka_video_url1 = mihyouka_video_url_list[0],
    mihyouka_video_title2 = mihyouka_video_title_list[1],mihyouka_video_url2 = mihyouka_video_url_list[1],
    mihyouka_video_title3 = mihyouka_video_title_list[2],mihyouka_video_url3 = mihyouka_video_url_list[2],
    mihyouka_video_id1 = mihyouka_video_id_list[0],mihyouka_video_id2 = mihyouka_video_id_list[1],mihyouka_video_id3 = mihyouka_video_id_list[2],
    video_length1 = video_length[0],video_length2=video_length[1],video_length3=video_length[2],
    score1 = score_list[0],score2 = score_list[1],score3 = score_list[2],
    video_score1 = video_score_list[0],video_score2 = video_score_list[1],video_score3 = video_score_list[2]
    )


if __name__ == '__main__':
   app.run(debug = True)